Android
0
Вклад в тег
@Override
protected Bitmap doInBackground(String... params) {
int count;
try {
URL url = new URL(params[0]);
URLConnection connect = url.openConnection();
connect.connect();
int lengthOfFile = connect.getContentLength();
input = new BufferedInputStream(url.openStream());
output = new FileOutputStream("sdcard/downloaded_photo.jpg");
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
Thread.sleep(100);
total += count;
publishProgress("" + (int) ((total * 100) / lengthOfFile));
output.write(data, 0, count);
}