简体   繁体   中英

Android programmatically update application when a new version is available in api 24 and api 25

I am trying to update my App in Nougat but I couldnt, I am getting the below error

code

File o = new File(String.valueOf(uri));
Uri myURI= FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", o);
Intent promptInstall = new Intent(Intent.ACTION_INSTALL_PACKAGE);
promptInstall.setDataAndType(myURI, "application/vnd.android.package-archive");
promptInstall.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
promptInstall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(promptInstall);

error

Caused by: java.lang.SecurityException: Permission Denial: opening provider
android.support.v4.content.FileProvider from ProcessRecord{9dfaa8c
1646:com.google.android.packageinstaller/u0a17} (pid=1646, uid=10017) that is
not exported from uid 10173

Please Help me to Fix this issue

Finally i Found the Solution

long referenceId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
if(downloadReference == referenceId) {
Timber.d("Downloading of the new app version complete");
//start the installation of the latest version
Intent installIntent = new Intent(Intent.ACTION_VIEW);
installIntent.setDataAndType(dm.getUriForDownloadedFile(downloadReference),
                                    "application/vnd.android.package-archive")
installIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(installIntent);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM