Is this correct? It works accordingly. But I m not sure about the
performance issues. I am relatively new to Android.
Please help
private void testDownload1(String urlStr) {
try {
progress = 0;
URL sourceURL = new URL(urlStr);
URLConnection con = sourceURL.openConnection();
InputStream inStream=(InputStream)con.getContent();
pbMax =con.getContentLength();
// max
length of the progress bar
FileOutputStream outStream = new
FileOutputStream("sdcard/
tmz1.tr3");
byte[] bytes = new byte[20480];
int readBytes = inStream.read(bytes);
while (readBytes > 0) {
try {
Thread.sleep(time);
} catch (InterruptedException e) {
e.printStackTrace();
}
this.runOnUiThread(new Runnable() {
public void run() {
pBar.setProgress(progress);
pBar.invalidate();
}
});
outStream.write(bytes, 0, readBytes);
readBytes = inStream.read(bytes);
progress += readBytes;
}
inStream.close();
outStream.close();
} catch (IOException e) {
Log.e(TAG, "error:" + e.toString());
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---