私のアプリケーションは、いくつかの大きなファイルをダウンロードする必要があります。ダウンロードにサービスを使用し、通知で進行状況を表示します。問題は、そのダウンロード時間中に、ユーザーが 3g から WIFI に切り替えることができることです。その場合、進行は停止しますが、例外はスローされません。この状況を適切に処理するにはどうすればよいですか?
URL url = new URL(myurl);
URLConnection conexion = url.openConnection();
conexion.setReadTimeout(10000);
conexion.setConnectTimeout(10000);
conexion.connect();
int lenghtOfFile = conexion.getContentLength();
// downlod the file
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(targetFilePath);
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
// publishing the progress....
updateProgress(downloadNM, downloadNotification, (int)total*100/lenghtOfFile);
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();