ダウンロードしたファイルを Okio でキャンセルしたいのですが、AsyncTaks で実行されます
@Override
protected String doInBackground(String... strings) {
for(int i=0; i<fileList.size(); i++) {
if (Utils.getStatusAbort()) {
request = new Request.Builder().url(fileList.get(i))
.addHeader("Authorization", header)
.addHeader("Content-Type", "application/json")
.build();
try {
okhttp3.Response response = client.newCall(request).execute();
ResponseBody body = response.body();
int finalI = i;
ZipFile zipFile;
if (response.isSuccessful()) {
try {
Log.i("body", "" + body);
destFilePath = Utils.getDestFilePath(context, fileNameList.get(i));
downloadedFile = new File(destFilePath, fileNameList.get(i));
BufferedSink sink = Okio.buffer(Okio.sink(downloadedFile));
if (response.body() != null) {
sink.writeAll(response.body().source());
}
sink.close();
Utils.savedStateOfApp(context, "publish");
//Log.i("md5:" + md5List.get(i), " = " + Utils.calculateMD5(new File(Utils.getDestFilePath(context, fileNameList.get(i)) + "/" + fileNameList.get(i))));
} catch (Exception e) {
e.printStackTrace();
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
}