Java Android N上安装应用程序时出现包解析错误

Java Android N上安装应用程序时出现包解析错误,java,android,Java,Android,我的应用程序没有出现在Play Market中,所以我在其中实现了自动更新功能。基本上是这样的: 在应用程序启动时询问后端是否有新版本 如果有新版本,请使用系统下载服务将APK下载排队(获得写入\u外部\u存储权限后) 下载完成后,使用以下代码段启动应用程序安装: Intent i = new Intent(); i.setAction(Intent.ACTION_VIEW); i.setDataAndType(Uri.fromFile(new File(fileUri.getPath())),

我的应用程序没有出现在Play Market中,所以我在其中实现了自动更新功能。基本上是这样的:

  • 在应用程序启动时询问后端是否有新版本
  • 如果有新版本,请使用系统下载服务将APK下载排队(获得写入\u外部\u存储权限后)
  • 下载完成后,使用以下代码段启动应用程序安装:

    Intent i = new Intent();
    i.setAction(Intent.ACTION_VIEW);
    i.setDataAndType(Uri.fromFile(new File(fileUri.getPath())), "application/vnd.android.package-archive");
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(i);
    
  • 在SDK级别为22或更低的设备上,一切都进行得很顺利,但当我尝试在Android 6上更新应用程序时,会收到消息“Parse Error:解析包时出现问题。” 以下是my build.gradle中的代码片段:

    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.1"
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
        defaultConfig {
            applicationId "app.id"
            minSdkVersion 14
            targetSdkVersion 23
            versionCode 22
            versionName "1.3.3"
            generatedDensities = []
        }
        aaptOptions {
            additionalParameters "--no-version-vectors"
        }
        buildTypes {
            release {
                minifyEnabled true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        packagingOptions {
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/NOTICE'
        }
        testOptions {
            unitTests.returnDefaultValues = true
        }
    }
    
    当我使用浏览器下载相同的APK并使用文件管理器开始安装时,安装进展顺利。
    有人知道如何解决这个问题吗?

    @Tez认为解决方案行不通。如果它是其中之一,那么问题将出现在所有API级别的设备上,但这是安卓6特有的。@FyodorSherstobitov;你已经解决了这个问题,仍然与文件提供商我面临这个问题。