if (!new File("/sdcard/tnr/receive/" + item_name + "/tnr_contents.zip").exists()) {
RequestParams params = new RequestParams();
params.put("mod", "down");
params.put("item_num", item_num);
shopHttpClient = new com.loopj.android.http.AsyncHttpClient();
shopHttpClient.post(Constant.SERVER_URL + "shop_down.php"
+ "?item_num=" + item_num, params, new JsonHttpResponseHandler() {
@Override
public void onStart() {
super.onStart();
}
@Override
public void onFailure(Throwable e, JSONObject errorResponse) {
super.onFailure(e, errorResponse);
Log.d(Constant.LOOPJ_TAG, errorResponse.toString());
}
@Override
public void onFinish() {
super.onFinish();
}
@Override
public void onSuccess(JSONObject response) {
super.onSuccess(response);
Log.d("JsonObject", response.toString());
try {
JSONObject jsonObject = new JSONObject(response.toString());
String item_src = jsonObject.getString("item_src");
/**
* Download contents zip file
*/
String[] allowedTypes = new String[] {
"application/zip", "image/png"
};
// download binary data;
new com.loopj.android.http.AsyncHttpClient().post(Constant.SERVER_URL + item_src, new BinaryHttpResponseHandler(allowedTypes) {
ProgressDialog progressDialog = new ProgressDialog(getActivity());
@Override
public void onStart() {
super.onStart();
Log.d(Constant.LOOPJ_TAG, "onStart");
if (!progressDialog.isShowing()) {
progressDialog.show(getActivity(), "", "Contents downloading...", true);
progressDialog.setCancelable(true);
}
}
@Override
public void onSuccess(byte[] binaryData) {
super.onSuccess(binaryData);
Log.d(Constant.LOOPJ_TAG, "onSuccess");
Utils.getDir("/tnr/receive/" + item_name);
try {
FileOutputStream outputStream = new FileOutputStream(new File("/sdcard/tnr/receive/" + item_name + "/tnr_contents.zip"));
outputStream.write(binaryData);
outputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (new File("/sdcard/tnr/receive/" + item_name + "/tnr_contents.zip").exists()) {
try {
ZipManager.unzip("/sdcard/tnr/receive/" + item_name + "/tnr_contents.zip", "/sdcard/tnr/receive/" + item_name + "/", false);
Log.d("ZipManager", "Complete");
} catch (Exception e) {
e.printStackTrace();
}
}
progressDialog.hide();
progressDialog.dismiss();
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] binaryData, Throwable error) {
super.onFailure(statusCode, headers, binaryData, error);
}
@Override
public void onProgress(int bytesWritten, int totalSize) {
super.onProgress(bytesWritten, totalSize);
}
@Override
public void onFinish() {
}
});
} catch (JSONException e) {
e.printStackTrace();
}
}
});
안녕하세요, 현재 loopj의 android-async-http를 사용해서 zip 파일을 다운로드받는 걸 구현하고 있는데요. 기능 자체는 다 구현했는데 ProgressDialog가 이상하게 dismiss되지 않네요. new AsyncHttpClient 에서 onFinish에도 해보았는데 안되는군요. 어떻게 해야할까요?