Instant App:RuntimeException:无法获取提供程序FileProvider:SecurityException:Provider必须授予uri权限

时间:2018-02-13 16:40:18

标签: android android-manifest android-fileprovider android-instant-apps

我尝试在我的应用中添加即时应用功能,但在以即时应用启动我的应用时,我收到此错误:

  

RuntimeException:无法获取提供者android.support.v4.content.FileProvider:java.lang.SecurityException:提供者必须授予uri权限

以下是我在feature清单中使用它的方式:

<manifest>

    <application>

        <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="${applicationId}.provider"
            android:exported="false"
            android:grantUriPermissions="true">

            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths" />

        </provider>

    </application>

</manifest>

我的即时应用build.gradle

apply plugin: 'com.android.instantapp'

android {
    compileSdkVersion rootProject.compileSdk

    defaultConfig {
        applicationId "applicationId" // same than my app's APK module
        minSdkVersion rootProject.minSdk
        targetSdkVersion rootProject.compileSdk
        versionCode rootProject.versionCode
        versionName rootProject.versionName
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

    }
}
dependencies {
    implementation project(':feature') // app's feature
}

有什么问题?谢谢你的帮助。

编辑:这是完整的logcat:

02-13 17:51:28.501 28992-28992/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                   Process: package, PID: 28992
                                                   java.lang.RuntimeException: Unable to get provider android.support.v4.content.FileProvider: java.lang.SecurityException: Provider must grant uri permissions
                                                       at android.app.ActivityThread.installProvider(ActivityThread.java:6206)
                                                       at android.app.ActivityThread.installContentProviders(ActivityThread.java:5721)
                                                       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5639)
                                                       at android.app.ActivityThread.-wrap2(ActivityThread.java)
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1637)
                                                       at android.os.Handler.dispatchMessage(Handler.java:105)
                                                       at android.os.Looper.loop(Looper.java:156)
                                                       at android.app.ActivityThread.main(ActivityThread.java:6523)
                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)
                                                    Caused by: java.lang.SecurityException: Provider must grant uri permissions
                                                       at android.support.v4.content.FileProvider.attachInfo(FileProvider.java:375)
                                                       at android.app.ActivityThread.installProvider(ActivityThread.java:6203)
                                                       at android.app.ActivityThread.installContentProviders(ActivityThread.java:5721) 
                                                       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5639) 
                                                       at android.app.ActivityThread.-wrap2(ActivityThread.java) 
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1637) 
                                                       at android.os.Handler.dispatchMessage(Handler.java:105) 
                                                       at android.os.Looper.loop(Looper.java:156) 
                                                       at android.app.ActivityThread.main(ActivityThread.java:6523) 
                                                       at java.lang.reflect.Method.invoke(Native Method) 
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941) 
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831) 
02-13 17:51:28.535 28932-28944/? E/Isotope: UID: [10188]  PID: [28932] IActivityManagerProxy : Instant app: package crashed: java.lang.RuntimeException: Unable to get provider android.support.v4.content.FileProvider: java.lang.SecurityException: Provider must grant uri permissions
                                                at android.app.ActivityThread.installProvider(ActivityThread.java:6206)
                                                at android.app.ActivityThread.installContentProviders(ActivityThread.java:5721)
                                                at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5639)
                                                at android.app.ActivityThread.-wrap2(ActivityThread.java)
                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1637)
                                                at android.os.Handler.dispatchMessage(Handler.java:105)
                                                at android.os.Looper.loop(Looper.java:156)
                                                at android.app.ActivityThread.main(ActivityThread.java:6523)
                                                at java.lang.reflect.Method.invoke(Native Method)
                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)
                                             Caused by: java.lang.SecurityException: Provider must grant uri permissions
                                                at android.support.v4.content.FileProvider.attachInfo(FileProvider.java:375)
                                                at android.app.ActivityThread.installProvider(ActivityThread.java:6203)
                                                at android.app.ActivityThread.installContentProviders(ActivityThread.java:5721) 
                                                at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5639) 
                                                at android.app.ActivityThread.-wrap2(ActivityThread.java) 
                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1637) 
                                                at android.os.Handler.dispatchMessage(Handler.java:105) 
                                                at android.os.Looper.loop(Looper.java:156) 
                                                at android.app.ActivityThread.main(ActivityThread.java:6523) 
                                                at java.lang.reflect.Method.invoke(Native Method) 
                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941) 
                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831) 

1 个答案:

答案 0 :(得分:1)

O 似乎不支持FileProvider ,因为其他应用不允许看到其ContentProvider

我有一个测试应用程序可用作 已安装的 应用程序但不能用作 instant app 。看起来即时应用不允许使用grantUriPermission(授予URI权限)(根据安装的应用无法看到即时应用的政策,这是有意义的ContentProvider不可见)。

这意味着即时应用无法检索使用ACTION_IMAGE_CAPTURE拍摄的照片(因为它们无法读取外部存储空间而相机应用无法写入即时应用的私有存储空间)。