Tôi đang cố gắng để tải về tập tin lớn từ Internet (> 20Mb)Android: tải tập tin lớn
private class DownloadTask extends AsyncTask<DatabaseInfo, Integer, String> {
private DatabaseInfo info;
protected String doInBackground(DatabaseInfo... dbInfo) {
int count;
info = dbInfo[0];
try {
URL url = new URL(dbInfo[0].dbPath);
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream("/sdcard/db.zip");
byte data[] = new byte[1024];
int total = 0;
while ((count = input.read(data)) != -1) {
//output.write(data, 0, count);
total += count;
if (total % 10240 == 0) {
publishProgress(total);
}
}
output.flush();
output.close();
input.close();
}
catch (Exception e) {
Log.e("err", e.getMessage());
}
return null;
}
protected void onProgressUpdate(Integer... total) {
int perc = (int) ((float) total[0]/(float) info.dbZipSize * 100);
mProgressDialog.setProgress(perc);
}
protected void onPostExecute(String s) {
dismissDialog(DIALOG_PROGRESS);
Log.e("err", "finish!");
}
}
Nếu tôi bỏ ghi chú dòng
//output.write(data, 0, count);
sau 7-15% thoại tải progressbar sa thải và Tôi thấy "kết thúc!" trong Log. Tại sao?
bạn đã thử trên thiết bị hoặc trình mô phỏng? nếu bạn đã thử nó trong trình giả lập thì nó không hoạt động đúng. vì bạn cần cấu hình hệ thống cao. – Praveen
giả lập. ok, tôi sẽ thử trên thiết bị – embo
có, trên thiết bị hoạt động tốt! – embo