I have this technique in my application and it is work quality however at android 11(Xiaomi) whilst APN is on it is now not running. In debug mode, the whole thing turns and does not "thunder", however, the document simply does not download. Additionally, the receiver didn't get a hold of the download reference. And all that is happened handiest whilst APN is on. I think that and settings are good enough due to the fact I have communication whit, my WCF provider.
public void showUpdatePromtDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(OrmBaseActivity.this);
builder.setMessage("Налична е нова версия на приложението. За да продължите работа
трябва да го обновите сега. Натиснете бутон 'Обнови' за да продължите.")
.setCancelable(false)
.setPositiveButton("Обнови", new DialogInterface.OnClickListener() {
//if the user agrees to upgrade
public void onClick(DialogInterface dialog, int id) {
try {
//deletes old APKs in the directory
File dir = new File(OrmBaseActivity.this.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)+"");
if (dir.isDirectory())
{
String[] children = dir.list();
for (int i = 0; i < children.length; i++)
{
new File(dir, children[i]).delete();
}
}
//start downloading the file using the download manager
downloadManager = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
String url = getURL().replace("myServices.svc", "");
Uri Download_Uri = Uri.parse(url + "ApkLatestVersion/myFile.apk");
DownloadManager.Request request = new DownloadManager.Request(Download_Uri);
/*request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE);*/
request.setAllowedOverRoaming(false);
request.setTitle("myAPP App Download");
request.setDestinationInExternalFilesDir(OrmBaseActivity.this, Environment.DIRECTORY_DOWNLOADS,"myFile.apk");
downloadReference = downloadManager.enqueue(request);
} catch (Exception e) {
e.printStackTrace();
dialog.dismiss();
Toast.makeText(OrmBaseActivity.this, "Възникна грешка. Моля, опитайте отново.", Toast.LENGTH_SHORT).show();
}
}
});
/*.setNegativeButton("За по-късно", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});*/
//show the alert message
builder.create().show();
}
0 Replies