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.get(url,
new
FileAsyncHttpResponseHandler(
this
) {
int
total = CommonUtil.APK_TOTAL_SIZE;
@Override
public
void
onProgress(
int
bytesWritten,
int
totalSize) {
int
progress_temp = (
int
) bytesWritten *
100
/ total;
mProgressDialog.setProgress(progress_temp);
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();
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() ,
"예"
,
"아니오"
);
}
});
}