小编Edu*_*uOK的帖子

意图安装APK文件 - Android Nougat

我广泛搜索并没有发现问题.当您尝试APK file使用Intentin 安装时Android Nougat,它只是不安装并显示以下警告:"解析包时出现问题".

它可以完美地打开PDF文件,例如,使用设置来打开这种类型的文件(.PDF).但要安装.apk文件不起作用.

LogCat 没有显示任何错误,我无法达成任何解决方案.

可能有什么不对?

以下代码:

清单:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />

<provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="br.com.xxxxxx.xxxxxx.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/filepaths"/>
    </provider>
Run Code Online (Sandbox Code Playgroud)

XML /文件路径:

<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="storage/emulated/0" path="."/>
Run Code Online (Sandbox Code Playgroud)

活动:

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        try {
            Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
            File file = new File(getContext().getFilesDir(), "app-debug.apk");
            Uri uri = FileProvider.getUriForFile(getContext(), BuildConfig.APPLICATION_ID + ".fileprovider", file);

            intent.setDataAndType(uri, "application/vnd.android.package-archive");
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            startActivity(intent);
            finish();
        } …
Run Code Online (Sandbox Code Playgroud)

android android-intent apk android-install-apk android-7.0-nougat

8
推荐指数
1
解决办法
2964
查看次数