をService
使用してダウンロード タスクを管理する がありますHttpURLConnection
。
HTTP リクエストを実行する前にカスタムisNetworkAvailable
メソッドを使用していますが、リクエスト中に失われた接続をどのように管理するのか疑問に思っています。
ループ内isNetworkAvailable
でメソッドを呼び出す必要がありますか (つまり、多くの呼び出しを意味します)。while
で失われた接続を管理する標準的な方法は何HttpURLConnection
ですか?
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
FileOutputStream outputStream = openFileOutput(filename, MODE_PRIVATE | MODE_APPEND);
BufferedInputStream in = new BufferedInputStream(connection.getInputStream());
byte[] data = new byte[1024];
int x = 0;
while ((x = in.read(data, 0, 1024)) >= 0) {
outputStream.write(data, 0, x);
}