【发布时间】:2020-05-06 06:51:27
【问题描述】:
我正在尝试以“Work Profile”模式 (BYOD) 以编程方式安装 apk。但是有一个我无法解决的问题:无法在 android 版本 7.0(24) 和 7.1(25) 中安装 apk。弹出对话框显示此消息:
您的管理员不允许安装从 来源不明
瞧,我是怎么做的:
val uri = FileProvider.getUriForFile(context,authority,File(filePath))
val openFileIntent = Intent(Intent.ACTION_VIEW)
openFileIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
openFileIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
openFileIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
openFileIntent.data = uri
context.startActivity(openFileIntent)
在清单中:
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths"
tools:replace="android:resource" />
</provider>
还有file_provider_paths.xml:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="external"
path="." />
<external-files-path
name="external_files"
path="." />
<files-path
name="files"
path="." />
</paths>
【问题讨论】:
-
您是否尝试在您的设备设置中允许安装来自未知来源的应用程序?
-
@lenik 是的,但它不起作用
标签: android kotlin android-work-profile