android - 在 SDK 26 中从本地存储安装 APK 时出现问题
问题描述
我有一种方法可以进行应用程序更新,该方法在 sdk 版本 26 之前可以完美运行。
在 26 中,它打开 Activity,然后立即再次关闭它,而不会引发任何(明显的)异常或警告。
我没有看到任何有关新权限或任何必要内容的文档。如果我只是将 minSdkVersion 更改为 25,它会再次正常工作。
很想知道 26 有什么变化以及如何解决它。
这是相关的代码段,但正如我所说,它并没有“损坏”——它只是在 26 中默默地失败了。
if (Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.M) {
Log.d(TAG, "Marshmallow or lower");
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
}
//if version 24 or above
else {
Log.d(TAG, "higher than Marshmallow");
Uri uri = FileProvider.getUriForFile(mContext, mContext.getApplicationContext().getPackageName() + ".provider", file);
intent.setDataAndType(uri, "application/vnd.android.package-archive");
}
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
mContext.startActivity(intent);
解决方案
您是否尝试将以下权限添加到清单?
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
Android Oreo 中进行了一些更改,以使从 Playstore 外部安装应用程序更安全。您可以在以下链接获取更多信息:
https://android-developers.googleblog.com/2017/08/making-it-safer-to-get-apps-on-android-o.html
推荐阅读
- django - 禁用“记住每个 SQL 查询”(Django)
- css - CSS page-break-inside/after/before 避免不起作用
- python - 如何在python中声明多个相似的变量?
- python - 在python中继承线程类
- python - Photoshop的“黑白”调整层背后的算法是什么?
- android - 从 Android 导航栏中删除后退按钮
- angular - 如何将变压器管道添加到http?
- python - 熊猫,根据具有某些值的先前行中的值创建新列
- ruby-on-rails - Rails 5.2 API - 返回 JSON 中的枚举值
- php - PHP和表单在同一页面上