Reputation:
I am using this code to upload file from my android to a server but I dont know how much of my file is uploaded( for example 30MB
from 100MB
)!
Is there any way?
String url = "http://yourserver";
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),
"yourfile");
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
InputStreamEntity reqEntity = new InputStreamEntity(
new FileInputStream(file), -1);
reqEntity.setContentType("binary/octet-stream");
reqEntity.setChunked(true); // Send in multiple parts if needed
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
//Do something with response...
} catch (Exception e) {
// show error
}
Upvotes: 0
Views: 867
Reputation: 128
hello for working with internet you must to use new Thread but in thread we can't access main thread so make a new runonuithread and change progress from it
new Thread(new Runnable() {
@Override
public void run() {
/*
upload codes goes here
*/
runOnUiThread(new Runnable() {
@Override
public void run() {
//set value of progressbar here
}
});
}
}).start();
Upvotes: 1
Reputation: 20990
For that you have use AsyncTask
and set ProgressDialog
percent using publishProgress()
method. For more detail visit this link.
Upvotes: 2