当api 24和api 25中有新版本时,Android以编程方式更新应用程序

时间:2017-03-27 10:44:06

标签: java android android-layout android-fragments

我正在尝试在Nougat中更新我的应用程序,但我无法,我收到以下错误

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);

错误

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

请帮我解决此问题

1 个答案:

答案 0 :(得分:0)

最后我找到了解决方案

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);