public void DownloadApk(String fileurl,String dirPath,String filename)
{
OKHTTP_SSL ssl =new OKHTTP_SSL(context);
AndroidNetworking.download(fileurl,dirPath,filename)
.setTag("downloadTest")
.setPriority(Priority.MEDIUM)
.setOkHttpClient(ssl.Okhttpclient())
.setPercentageThresholdForCancelling(50) // even if at the time of cancelling it will not cancel if 50%
.build() // downloading is done.But can be cancalled with forceCancel.
.setDownloadProgressListener(new DownloadProgressListener() {
@Override
public void onProgress(long bytesDownloaded, long totalBytes) {
// do anything with progress
}
})
.startDownload(new DownloadListener() {
@Override
public void onDownloadComplete() {
// do anything after completion
Toast.makeText(context, "File Download Sucessfully", Toast.LENGTH_SHORT).show();
ShowAlert();
}
@Override
public void onError(ANError error) {
// handle error
Toast.makeText(context, "Error file download"+error.toString(), Toast.LENGTH_SHORT).show();
}
});
}
private void ShowAlert() {
// TODO Auto-generated method stub
try {
HideDialog();
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setMessage("Do you want to upadte app..!");
alertDialogBuilder.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(filefullpath)), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // without this flag android returned a intent error!
context.startActivity(intent);
alertDialog.hide();
}
});
alertDialogBuilder.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
alertDialog.hide();
}
});
alertDialog = alertDialogBuilder.create();
alertDialog.show();
} catch (Exception e) {
// TODO: handle exception
}
}
{
OKHTTP_SSL ssl =new OKHTTP_SSL(context);
AndroidNetworking.download(fileurl,dirPath,filename)
.setTag("downloadTest")
.setPriority(Priority.MEDIUM)
.setOkHttpClient(ssl.Okhttpclient())
.setPercentageThresholdForCancelling(50) // even if at the time of cancelling it will not cancel if 50%
.build() // downloading is done.But can be cancalled with forceCancel.
.setDownloadProgressListener(new DownloadProgressListener() {
@Override
public void onProgress(long bytesDownloaded, long totalBytes) {
// do anything with progress
}
})
.startDownload(new DownloadListener() {
@Override
public void onDownloadComplete() {
// do anything after completion
Toast.makeText(context, "File Download Sucessfully", Toast.LENGTH_SHORT).show();
ShowAlert();
}
@Override
public void onError(ANError error) {
// handle error
Toast.makeText(context, "Error file download"+error.toString(), Toast.LENGTH_SHORT).show();
}
});
}
private void ShowAlert() {
// TODO Auto-generated method stub
try {
HideDialog();
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setMessage("Do you want to upadte app..!");
alertDialogBuilder.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(filefullpath)), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // without this flag android returned a intent error!
context.startActivity(intent);
alertDialog.hide();
}
});
alertDialogBuilder.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
alertDialog.hide();
}
});
alertDialog = alertDialogBuilder.create();
alertDialog.show();
} catch (Exception e) {
// TODO: handle exception
}
}
Comments
Post a Comment