private void apkInstall() {
String url = CommonUtil.Server.getURL_DOWNLOAD();
final ProgressDialog mProgressDialog = new ProgressDialog(this);
mProgressDialog.setMessage(ErrorCode.Ing_Download.getMessage_Wait());
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setCancelable(false);
mProgressDialog.show();
AsyncHttpClient client = new AsyncHttpClient();
//client.setURLEncodingEnabled(false);
client.get(url, new FileAsyncHttpResponseHandler(this) {
int total = CommonUtil.APK_TOTAL_SIZE;
@Override
public void onProgress(int bytesWritten, int totalSize) {
// int float 형변환 때문에 꼬임.. 그래서 이렇게 만듬..
float progress_temp = ((float)bytesWritten)/((float)total);
progress_temp = progress_temp*100;
int progress = (int)progress_temp;
mProgressDialog.setProgress(progress);
super.onProgress(bytesWritten, totalSize);
}
@Override
public void onSuccess(int statusCode, Header[] headers, File response) {
mProgressDialog.dismiss();
try {
File SDCardRoot = Environment.getExternalStorageDirectory();
File file = new File(SDCardRoot,"SBBMobile.apk");
FileOutputStream fileOutput = new FileOutputStream(file);
Log.e("DOWNLOAD", "fileoutput");
FileInputStream fin = new FileInputStream(response);
byte[] buffer = new byte[1024];
int bufferLength = 0;
while ( (bufferLength = fin.read(buffer)) > 0 ) {
fileOutput.write(buffer, 0, bufferLength);
}
fin.close();
fileOutput.close();
//Log.i(LOG_TAG, response.getAbsolutePath() + file.getAbsolutePath() );
Intent intent2 = new Intent(Intent.ACTION_VIEW);
intent2.setDataAndType( Uri.fromFile(file), "application/vnd.android.package-archive");
startActivity(intent2);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(int arg0, Header[] arg1, Throwable arg2, File arg3) {
mProgressDialog.dismiss();
showAlertDialog(ErrorCode.FAIL_Download.getCode() ,ErrorCode.FAIL_Download.getMessage_Restart() ,"예", "아니오");
}
});
}
파일 다운로드 하는 소스는 위와 같습니다.
문제는 OS 가 롤리팝인 경우에.. 위와 같이 다운로드를 하면.. 정상적이지 않은 APK 파일이 되어서
설치할 때 구문분석오류가 납니다..
기타 다른 OS들은 문제가 없습니다.. 왜 그런지, 어떻게 해결해야되는지 아시는분 계신가요.. 어제 오늘 아주 답답합니다 ㅠㅠ