私は asynctask を使用してファイルをダウンロードしています。Androidのwifi接続をオフにするまで(他のインターネット接続はありません)、ダイアログをダウンロードして変更を加えるまで、正常に動作します。ログで確認するとinputstreamの関数read()がノンストップであることがわかりました。では、このケースを確認するにはどうすればよいでしょうか。ここに私のコードがあります:
URL url = new URL(this.url);
URLConnection connection = url.openConnection();
connection.setReadTimeout(1000);
connection.connect();
// this will be useful so that you can show a typical 0-100% progress bar
int fileLength = connection.getContentLength();
fileName = "temp.zip";
// download the file
InputStream input = new BufferedInputStream(connection.getInputStream());
OutputStream output = new FileOutputStream(path+fileName);
byte buffer[] = new byte[1024000];
long total = 0;
int count;
Log.v("test download:","download in background");
while (((count = input.read(buffer)) != -1)) {
Log.v("test download:","read:"+count);
total += count;
publishProgress((int) (total * 100 / fileLength - 1));
output.write(buffer, 0, count);
}