[R&D] Upload files with DropBox - Galaxy S II Android Development

Hi, this is my code, i cant get upload a simple file:
Signgin in to DropBox:
.....private AccessTokenPair tokensDB;
.....private DropboxAPI<AndroidAuthSession> mDBApi;
.....final static private AccessType ACCESS_TYPE = AccessType.DROPBOX;
.....AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
.....AndroidAuthSession sesDropBox = new AndroidAuthSession(appKeys, ACCESS_TYPE);
.....mDBApi = new DropboxAPI<AndroidAuthSession>(sesDropBox);
.....mDBApi.getSession().startAuthentication(this);
When activity resums this code is executed:
.....mDBApi.getSession().finishAuthentication();
.....tokensDB = mDBApi.getSession().getAccessTokenPair();
when the user clicks over a button in same activity next code is executed:
protected void subeArchivos() {
.....// Uploading content.
.....String fileContents = "Hello World, this is only an example!!";
.....ByteArrayInputStream inputStream = new ByteArrayInputStream(fileContents.getBytes());
.....try {
..........mDBApi.putFile("/testing.txt", inputStream, fileContents.length(), null, null);
..........//Log.i("DbExampleLog", "The uploaded file's rev is: " + newEntry.rev);
.....} catch (DropboxUnlinkedException e) {
..........// User has unlinked, ask them to link again here.
..........Log.e("DbExampleLog", "User has unlinked.");
.....} catch (DropboxException e) {
..........toast = Toast.makeText(getApplicationContext(), "C U A: " + e.getMessage(), Toast.LENGTH_SHORT);
..........toast.show();
..........//Log.e("DbExampleLog", "Something went wrong while uploading.");
.....}
}
The code in red throws error. and after the conde in yellow is executed.
My mnifiest permissions are:
.....<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
.....<uses-permission android:name="android.permission.INTERNET"></uses-permission>
.....<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"></uses-permission>
P.D. All works, exept code in red!!
I hope you can help me!! thx!!

anyone??

I didn't understand anything exc. that you can't upload any file with Dropbox, but I had similar problem. Seems you shouldn't delete the Downloads app, else it bugs DB uploads.
Hope it helps.

thx man, every folder in his place, but maybe something in my code is wrong!!

Related

Signature Capture from web page

I am developing a PHP app that runs on an XDA2 PocketPC. It is for use by field engineers to book themselves to jobs whilst on-site, and it will update our internal stock system etc.
The need has arisen for signature capture, whereby a signature area is embedded into a web page and when the client signs the screen, it is transferred safely into a database at our offices.
I have looked at various possibilities but they all seem to rely on ASP/VBSCRIPT.
Has anyone ever come across something that will integrate with my PHP web app?
In a nutshell: Signature region in web page, user signs screen,signature data sent to a SQL database back at base.
Any ideas? :shock:
Hi limepickle
The webbrowser in WM2003 is really quite primitive in comparison to it's desktop counterparts these days. For that reason, i really do not think that you will find a way to do this in the browser.
I write software similar to that which you are talking about using .NET and i've considered using web pages once or twice for simpler apps, but signature capture was always the sticking point which I could never think of a way to acheive...
Sorry to disappoint you :roll:
Pope <><
limepickle said:
I am developing a PHP app that runs on an XDA2 PocketPC. It is for use by field engineers to book themselves to jobs whilst on-site, and it will update our internal stock system etc.
The need has arisen for signature capture, whereby a signature area is embedded into a web page and when the client signs the screen, it is transferred safely into a database at our offices.
I have looked at various possibilities but they all seem to rely on ASP/VBSCRIPT.
Has anyone ever come across something that will integrate with my PHP web app?
In a nutshell: Signature region in web page, user signs screen,signature data sent to a SQL database back at base.
Any ideas? :shock:
Click to expand...
Click to collapse
your gonna get stuck with a php version since the pocket IE isnt that great,
perhaps you can find a flash based signature capture and has flash on the pocket pcs?
this is our solution:
i created a custom application to do this for our company,
its developed using the OpenNet Compact Framework.
its a fullscreen signature app and when the rep is ready to upload the signature they click the send button that transfers it to a ASP.NET web service. this then saves the image as Jpeg to a shared folder and also to SQL for archiving,
check out:
http://www.opennetcf.org/CategoryView.aspx?category=Home
http://www.codeproject.com/netcf/Signature_Capture.asp
this is an example of the code to use in VS.NET with OpenNetCF.
Code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Xml;
namespace WGTools
{
/// <summary>
/// Summary description for frmSignatureCapture.
/// </summary>
public class frmSignatureCapture : System.Windows.Forms.Form
{
private OpenNETCF.Windows.Forms.Signature signature1;
private System.Windows.Forms.Button button1;
private OpenNETCF.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private Microsoft.WindowsCE.Forms.InputPanel inputPanel1;
private System.Windows.Forms.ToolBar toolBar1;
private OpenNETCF.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
Guid guid = Rico.Tools.PocketGuid.NewGuid();
public frmSignatureCapture()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmSignatureCapture));
this.groupBox1 = new OpenNETCF.Windows.Forms.GroupBox();
this.button1 = new System.Windows.Forms.Button();
this.signature1 = new OpenNETCF.Windows.Forms.Signature();
this.groupBox2 = new OpenNETCF.Windows.Forms.GroupBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.inputPanel1 = new Microsoft.WindowsCE.Forms.InputPanel();
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.button1);
this.groupBox1.Location = new System.Drawing.Point(8, 0);
this.groupBox1.Size = new System.Drawing.Size(224, 264);
this.groupBox1.Text = "New Signature";
//
// button1
//
this.button1.Location = new System.Drawing.Point(16, 120);
this.button1.Size = new System.Drawing.Size(192, 32);
this.button1.Text = "Create New Signature";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// signature1
//
this.signature1.BackColor = System.Drawing.Color.DimGray;
this.signature1.BackgroundBitmap = ((System.Drawing.Bitmap)(resources.GetObject("signature1.BackgroundBitmap")));
this.signature1.BorderColor = System.Drawing.Color.Black;
this.signature1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.signature1.ForeColor = System.Drawing.Color.White;
this.signature1.Location = new System.Drawing.Point(240, 0);
this.signature1.Size = new System.Drawing.Size(240, 320);
this.signature1.Text = "SignatureControl";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.button5);
this.groupBox2.Controls.Add(this.button4);
this.groupBox2.Controls.Add(this.textBox1);
this.groupBox2.Location = new System.Drawing.Point(488, 0);
this.groupBox2.Size = new System.Drawing.Size(224, 264);
this.groupBox2.Text = "Signature Details";
//
// textBox1
//
this.textBox1.AcceptsReturn = true;
this.textBox1.Location = new System.Drawing.Point(8, 24);
this.textBox1.Multiline = true;
this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBox1.Size = new System.Drawing.Size(208, 96);
this.textBox1.Text = "textBox1";
//
// button2
//
this.button2.Location = new System.Drawing.Point(240, 0);
this.button2.Size = new System.Drawing.Size(24, 20);
this.button2.Text = ">";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(240, 248);
this.button3.Size = new System.Drawing.Size(24, 20);
this.button3.Text = "c";
//
// button4
//
this.button4.Location = new System.Drawing.Point(32, 176);
this.button4.Size = new System.Drawing.Size(160, 20);
this.button4.Text = "Upload To HeadOffice";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button5
//
this.button5.Location = new System.Drawing.Point(32, 208);
this.button5.Size = new System.Drawing.Size(160, 20);
this.button5.Text = "Save To File";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// frmSignatureCapture
//
this.ClientSize = new System.Drawing.Size(1122, 265);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.signature1);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.toolBar1);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Text = "New Signature";
this.Load += new System.EventHandler(this.frmSignatureCapture_Load);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
this.ControlBox = false;
this.Menu = null;
this.signature1.Location = new System.Drawing.Point(0, 0);
this.button2.Location = new System.Drawing.Point(0, 0);
this.button3.Location = new Point(0,298);
this.Controls.Remove(this.toolBar1);
}
private void button2_Click(object sender, System.EventArgs e)
{
this.WindowState = FormWindowState.Normal;
this.ControlBox = true;
this.groupBox2.Location = new System.Drawing.Point(8,0);
this.button2.Visible = false;
this.button3.Visible = false;
this.signature1.Visible = false;
this.Controls.Add(this.toolBar1);
this.textBox1.Text = Convert.ToBase64String(this.signature1.GetSignatureEx(),0,this.signature1.GetSignatureEx().Length);
}
private void frmSignatureCapture_Load(object sender, System.EventArgs e)
{
}
private void button4_Click(object sender, System.EventArgs e)
{
//TEST - send the sig to the WS
WSSig.ws1 wssig = new WGTools.WSSig.ws1();
try
{
textBox1.Text = wssig.CaptureSignature_V1("xxxxxx","username","sigID","notes",this.signature1.GetSignatureEx());
}
catch(Exception e3)
{
textBox1.Text = e3.ToString();
}
}
private void button5_Click(object sender, System.EventArgs e)
{
if(Rico.Tools.Stuff.SaveSigToFile("rico","theid","notes",Convert.ToBase64String(this.signature1.GetSignatureEx(),0,this.signature1.GetSignatureEx().Length)))
MessageBox.Show("Saved To File","Saved",MessageBoxButtons.OK,MessageBoxIcon.Asterisk,MessageBoxDefaultButton.Button1);
this.textBox1.Text = "saved to file";
}
}
}
Yes, I think you're right, Flash will probably be the way to go, seeing as everyone seems to to be .NET / ASP crazy!!!!
LOL
PS. thanks Pope and djrm, I do appreciate you trying to help, its just that anything to do with .net vb etc, may as well be Urdu.
asp.net web signature capture control
You can try out http://mysignature.brinkster.net for this
Don't Necro old threads for shamelesly plugging your software..

Modify apk to add a file in a specified path

Hello all. I need some information on how i can modify an existing apk and add a file to a specified path during installation.
Better...i need that installation creates a file in data/data/com.myprogram.android/myfile where com.myprogram.android is the path of program data. Is that possible???
thx
*bump* - after one year, this is exactly what i also need!
any answer to this? since i modify an existing .apk, changing the java-code is not an option. solution must be pure .apk based / via the manifest
you could do it in a few steps
1) copy the apk to somewhere safe (/mnt/sdcard)
2) uninstall the apk, maybe use PackageManager
3) unzip the apk to a folder, add your changed/new files, zip up the folder again (extension .apk). Use busybox's zip/unzip if you need
4)sign the new apk using this (i tried it it works)
5)install the new+signed apk, maybe use PackageManager
fl3xo said:
Hello all. I need some information on how i can modify an existing apk and add a file to a specified path during installation.
Better...i need that installation creates a file in data/data/com.myprogram.android/myfile where com.myprogram.android is the path of program data. Is that possible???
thx
Click to expand...
Click to collapse
The way I've done this in the past is just store whatever it is you want to add in the res/raw directory of the project, then when the program first runs, copy the raw resource wherever you want it in the tree.
Code:
// Copy the helper app from resources to an executable in our classpath
protected void CopyExtraBin() {
// check if it's already there
File helper = new File("/data/data/com.mypath.myprog/helper_app");
if (helper.exists()) {
// already there, nothing to do.
return;
}
InputStream setdbStream = getResources().openRawResource(R.raw.helper_app);
try {
byte[] bytes = new byte[setdbStream.available()];
DataInputStream dis = new DataInputStream(setdbStream);
dis.readFully(bytes);
FileOutputStream setdbOutStream = new FileOutputStream(
"/data/data/com.mypath.myprog/helper_app");
setdbOutStream.write(bytes);
setdbOutStream.close();
// set executable permissions on our helper
Process process = Runtime.getRuntime().exec("sh");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("chmod 755 /data/data/com.mypath.myprog/helper_app\n");
os.writeBytes("exit\n");
os.flush();
} catch (Exception e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
return;
}
}
Gene Poole said:
The way I've done this in the past is just store whatever it is you want to add in the res/raw directory of the project, then when the program first runs, copy the raw resource wherever you want it in the tree.
Code:
// Copy the helper app from resources to an executable in our classpath
protected void CopyExtraBin() {
// check if it's already there
File helper = new File("/data/data/com.mypath.myprog/helper_app");
if (helper.exists()) {
// already there, nothing to do.
return;
}
InputStream setdbStream = getResources().openRawResource(R.raw.helper_app);
try {
byte[] bytes = new byte[setdbStream.available()];
DataInputStream dis = new DataInputStream(setdbStream);
dis.readFully(bytes);
FileOutputStream setdbOutStream = new FileOutputStream(
"/data/data/com.mypath.myprog/helper_app");
setdbOutStream.write(bytes);
setdbOutStream.close();
// set executable permissions on our helper
Process process = Runtime.getRuntime().exec("sh");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("chmod 755 /data/data/com.mypath.myprog/helper_app\n");
os.writeBytes("exit\n");
os.flush();
} catch (Exception e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
return;
}
}
Click to expand...
Click to collapse
where to insert it?
Moved to Q&A.
mishanet said:
Gene Poole said:
The way I've done this in the past is just store whatever it is you want to add in the res/raw directory of the project, then when the program first runs, copy the raw resource wherever you want it in the tree.
Code:
// Copy the helper app from resources to an executable in our classpath
protected void CopyExtraBin() {
// check if it's already there
File helper = new File("/data/data/com.mypath.myprog/helper_app");
if (helper.exists()) {
// already there, nothing to do.
return;
}
InputStream setdbStream = getResources().openRawResource(R.raw.helper_app);
try {
byte[] bytes = new byte[setdbStream.available()];
DataInputStream dis = new DataInputStream(setdbStream);
dis.readFully(bytes);
FileOutputStream setdbOutStream = new FileOutputStream(
"/data/data/com.mypath.myprog/helper_app");
setdbOutStream.write(bytes);
setdbOutStream.close();
// set executable permissions on our helper
Process process = Runtime.getRuntime().exec("sh");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("chmod 755 /data/data/com.mypath.myprog/helper_app\n");
os.writeBytes("exit\n");
os.flush();
} catch (Exception e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
return;
}
}
Click to expand...
Click to collapse
where to insert it?
Click to expand...
Click to collapse
Yeah I have the same question. I'm wanting to add some files to /data/data/<appdirectory>/lib but since it's permissions are set to drwxr-xr-x system system I can't write to it without changing apk itself.
I tried putting this into some code and I just alot of cannot find symbol errors and DataInputStream and Toast. I'm sure It's just my limited knowledge and maybe changes in android but this example code doesn't seem to work for me.
Gene Poole said:
The way I've done this in the past is just store whatever it is you want to add in the res/raw directory of the project, then when the program first runs, copy the raw resource wherever you want it in the tree.
Code:
// Copy the helper app from resources to an executable in our classpath
protected void CopyExtraBin() {
// check if it's already there
File helper = new File("/data/data/com.mypath.myprog/helper_app");
if (helper.exists()) {
// already there, nothing to do.
return;
}
InputStream setdbStream = getResources().openRawResource(R.raw.helper_app);
try {
byte[] bytes = new byte[setdbStream.available()];
DataInputStream dis = new DataInputStream(setdbStream);
dis.readFully(bytes);
FileOutputStream setdbOutStream = new FileOutputStream(
"/data/data/com.mypath.myprog/helper_app");
setdbOutStream.write(bytes);
setdbOutStream.close();
// set executable permissions on our helper
Process process = Runtime.getRuntime().exec("sh");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("chmod 755 /data/data/com.mypath.myprog/helper_app\n");
os.writeBytes("exit\n");
os.flush();
} catch (Exception e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
return;
}
}
Click to expand...
Click to collapse

Need help troubleshooting my code.

Ok so for these last three days i have been trying to get into the android game. I did the hello android tutorial and yea. that was boring lol, so i decided to try and create a program to temporarily fix the keyboard backlight issue being experienced by some ICS port users. i have only part of the code done but it does not execute at all. I am not sure whats the problem. I have writted additional pieces to this code but have not put them in the program as i want to figure out why it doesnt run before i add more and then clean it up.
Code:
package com.dri94.led;
import java.util.*;
import java.io.*;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class LEDLightActivity extends Activity {
/** Called when the activity is first created. */
@SuppressWarnings("null")
@Override
public void onCreate(Bundle savedInstanceState) {
final int SDK_INT;
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Scanner input = new Scanner(System.in);
DataOutputStream os = null;
TextView tv = new TextView(this);
tv.setText("Enter 'y' to turn on keyboard light or 'n' to turn it off");
String yOrN = input.next();
if (yOrN == "y") {
tv.setText("Enter SDK number 7 for GB devices or 14 for ICS devices. No other devices are supported at this time");
SDK_INT = input.nextInt();
if (SDK_INT == '7') {
try {
os.writeBytes("echo 255 > /sys/class/leds/keyboard-backlight/brightness\n"
+ "chmod 444 /sys/class/leds/keyboard-backlight/brightness\n");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else {
try {
os.writeBytes("echo 255 > /sys/class/leds/kpd_backlight_en\n"
+ "chmod 444 /sys/class/leds/kpd_backlight_en\n");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
Any logcat output? I don't have ICS so those paths aren't available on my device, but similar paths are symlinks and directories. Does your app have write permissions to kpd_backlight_en (or whatever the symlink points to)?
You have a lot of problems there, lets point some of them out,
Code:
DataOutputStream os = null;
Youre initializating your outputStream as null, wich is a problem consideering you use it for writing a file. Also there are so many easier ways to write files, for example, I propose this simple writing method
Code:
public static void WriteFile(String text, String file) {
try{
FileWriter fstream = new FileWriter(file);
BufferedWriter out = new BufferedWriter(fstream);
out.write(text);
out.close();
}catch (Exception e){
//Deal exception ;D
}
}
simple code usage will be then
Code:
WriteFile("255", "/sys/class/leds/keyboard-backlight/brightness");
Second error I found, comparing strings with "==", this
Code:
if (yOrN == "y")
is wrong, you should try with
Code:
if (yOrN.equals("y")) {
Another thing i dont understand is this
Code:
final int SDK_INT;
Why do you declare a variable as final, if you are gonna assign some value later, right here
Code:
SDK_INT = input.nextInt();
Last thing I found is also comparing an integer with string? I dont understand what you do there
Code:
if (SDK_INT == '7')
Also your way to manage user inputs would be better with a simple button (or toggleButton) for turn on/off lights, or even use SensorEventListener.
I hope I have helped you in some , just tell me if you need something. Good luck!
How should i initialize it? And thank you alot. Ima play with my code tomorrow. The last one though is comparing it with a character value. but this post helped alot. I appreciate it... Especially cause i made soooo many beginner mistakes. My professor would be disappointed
Sent from my XT862 using T
Questions or Problems Should Not Be Posted in the Development Forum
Please Post in the Correct Forums
Moving to Q&A
thanks i wasnt sure where to post this! ill remember that from now on

Ping app

hey guys,
Building an app that runs a ping command at the moment and I can't quite get it to work. If I modify the command to something that isn't a terminal command then it'll output my error statement but i can't get it to display the ping output. any help would be awesome. I know my outputs for my error are bad but it's an easy way to determine what path it's outputting.
package com.mycompany.myapp;
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import java.io.*;
import java.lang.Process;
public class MainActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TextView Text = new TextView(this);
Runtime runtime = Runtime.getRuntime();
try
{
Process proc = runtime.getRuntime().exec("system/bin/ping 192.168.1.1");
BufferedReader in = new BufferedReader(
new InputStreamReader(proc.getInputStream()));
String line = "null";
while ((line = in.readLine()) != null) {
Text.setText(in.readLine());
}
}
catch (Exception e)
{
String line="55";
Text.setText(line);
}
setContentView(Text);
}
}
Thanks for any help you guys can give me,
Adam
Hey,
Try using "system/bin/ping -c 1 192.168.1.1" instead.
And then add this line just after that:
Code:
proc.waitFor();
and while reading the output of the ping you might want to do it like this maybe?
Code:
String line = "";
String result = "";
while (line != null)
{
result = result + "\n" + line;
line = in.readLine();
}
Text.setText(result);
If you want to ping more than 1 packet I think it would be better to make a new thread and do proc.waitFor() in that thread. Then send a message using a handler to set the output of the ping to the TextView
k i have done that and that does make more sense but Im still getting a black screen on the output. i am testing on a Sony tab s and using AIDE (on the device) cause my eclipse is broken. this is how my code looks now,
package com.mycompany.myapp;
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import java.io.*;
import java.lang.Process;
public class MainActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TextView Text = new TextView(this);
Runtime runtime = Runtime.getRuntime();
try
{
Process proc = runtime.getRuntime().exec("system/bin/ping 192.168.1.1");
BufferedReader in = new BufferedReader(
new InputStreamReader(proc.getInputStream()));
String line = "null";
while ((line = in.readLine()) != null) {
Text.setText(in.readLine());
}
}
catch (Exception e)
{
String line="55";
Text.setText(line);
}
setContentView(Text);
}
}
Is there anything else I could be missing??
Thanks,
Adam
Hey, I think you posted the same code again.
I am not sure if you can read the process stream before it is complete and ping does take a long time to complete. So your main thread is blocking on it and it doesn't get to executing the setContentView.
Thats why I think going for a seperate thread is a better option.
so it would be better to put the ping into a new class and call on it when i need it??
Not a seperate class, a seperate thread to be more specific.
Even if you do put the ping code in a seperate class' method and call that method in onCreate it will still run on the your applications main thread.
What I was trying to say is something along the lines of the following code:
Code:
private TextView textView;
private Process process;
private Handler handler;
private Thread pingThread;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
textView = new TextView(this);
textView.setText("Pinging...");
setContentView(textView);
try
{
process = Runtime.getRuntime().exec("system/bin/ping -c 5 192.168.1.1");
handler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
try
{
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
String result = "";
while(line != null)
{
result = result + "\n" + line;
line = reader.readLine();
}
reader.close();
textView.setText(result);
}
catch(Exception e)
{
e.printStackTrace();
textView.setText("Error");
}
}
};
pingThread = new Thread()
{
@Override
public void run()
{
try
{
process.waitFor();
}
catch(Exception e)
{
e.printStackTrace();
}
handler.sendEmptyMessage(0);
}
};
pingThread.start();
} catch (Exception e)
{
e.printStackTrace();
}
}
I am not sure if this is exactly how you want your app to behave. There might be a better way of doing what you want than what I have suggested but I tested the above code and it works for me.
thats wicked, basically what want my program to do is to run a ping command through a usb to rj45 adapter. at the moment I just need it to do the ping command through wifi and once that was working I was going to set it up to go through usb.
I wonder if there's something I'm doing wrong like I'm build the apk in AIDE on the tablet or something, cause I'm still getting a black screen when booting the app.
If I error the code up a bit, Like put "system/bin/pi ....." instead I do get pinging on the app but no error output and if the code is fine then nothing displays
That is very strange :S.
If you use the incorrect command it works fine but when you use the correct command it doesn't?
Can you post your code? or provide more details if possible?
the code is just the code you posted cause I thought if a I could get it working with that code then modify it to what it needs to do, when the command is incorrect it displays "ping....." but doesn't display an error, I'm going to install eclipse and build the package with that and see how it goes. did you test on a tablet and what did you use to deploy the package?
Adz117 said:
the code is just the code you posted cause I thought if a I could get it working with that code then modify it to what it needs to do, when the command is incorrect it displays "ping....." but doesn't display an error, I'm going to install eclipse and build the package with that and see how it goes. did you test on a tablet and what did you use to deploy the package?
Click to expand...
Click to collapse
I think i know whats happening. It isnt the Ide and using eclipse wont make much of a difference.
Are you usIng something like -c 5 in the ping command? Cause if you aren't i think ping is Going to take a really long time and all you'll see on the screen is "Pinging..."
Yea I have got that in the command, when the code is correct and working I dont get anything all I get is a black screen. Its when I error the command up a bit that I get pinging
Sent from my Sony Tablet S using XDA
hey guys,
just got eclipse running and tested it on an avd emulator and it runs perfect, so the question is what would cause it not to run on my tablet?
I have no idea! I don't have access to an Android Tablet, so I can't test it out! I tested it out on my phone too and it works just fine.
One thing I can suggest though is:
Put log statements throughout the program to signify where the the control has reached. Then run it on your tablet. That should shed some light on where the code is failing on your tablet.
tested it on my phone which is running 2.3 and it failed on there as well, "ping......" would pop up for about a second then disappear, also if I use a command like ls instead of ping on my tablet it will work perfectly fine so I'm guessing for some reason past android 2.1 it doesn't like the ping command. any ideas?
I tested it out on phone with 2.2. Did you try putting log statements and checking where it is failing.
You could also add breakpoints in your code and run it?

[Q] GoogleMap resets and stops responding

Hi all..
I am not sure this is the right sub-forum to post in, but here goes.
I am working on an app that uses a GoogleMap and lots of overlays/markers. Controls and navigation is handled automatically (no direct user interaction with the map needed so far).
Things work the way I want right until the app pauses and goes into the background. When I resume the app the map has zoomed out to 0:0 and it doesn't react to animateMap or anything anymore. I can't seem to figure how I get it back to the state where it doesn't react to user interaction and actually updates with my markers and stuff..
Below are the three methods handling the map, and it doesn't seem to react on any of it after a resume. Any hints?
Code:
private void setupMap(){
getSupportFragmentManager().beginTransaction().replace(R.id.trackeractivity_map, new SupportMapFragment()).commit();
FragmentManager fragmentManager = getSupportFragmentManager();
SupportMapFragment supportMapFragment = (SupportMapFragment) fragmentManager.findFragmentById(R.id.trackeractivity_map);
mMap = supportMapFragment.getMap();
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
mMap.setMyLocationEnabled(true);
Log.d(TAG, "Max zoom level " + mMap.getMaxZoomLevel());
}
private void updateUserLocation(double lat, double lon){
Log.d(TAG, "updateUserLocation - " + lat + " : " + lon);
mLastLocationLat = lat;
mLastLocationLon = lon;
CameraPosition userPos = new CameraPosition(new LatLng(lat, lon), mMap.getMaxZoomLevel()-4, 0, 0);
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(userPos));
}
private void updateMapOverlay(double lat, double lon){
Log.d(TAG, "updateMapOverlay - " + lat + " : " + lon + " - Type " + mCurrentType);
MarkerOptions marker = new MarkerOptions();
marker.position(new LatLng(lat, lon));
marker.draggable(false);
marker.icon(BitmapDescriptorFactory.fromResource(getTypeDrawableID(mCurrentType)));
mMap.addMarker(marker);
}
Try to re flash Google apps package or restore any previous nandroid backup
FRIEND IF I HELPED YOU HIT THANKS
Androyash said:
Try to re flash Google apps package or restore any previous nandroid backup
FRIEND IF I HELPED YOU HIT THANKS
Click to expand...
Click to collapse
That, unfortunately, didn't help.. Still does the same thing.. Bugs the crap out of me..
Maybe it is just me, but how do i set UISettings on the map? There only seems to be a method to get them?
https://developers.google.com/maps/...erence/com/google/android/gms/maps/UiSettings

Categories

Resources