Instant App:RuntimeException:无法获取提供者 FileProvider:SecurityException:提供者必须授予 uri 权限
Instant App: RuntimeException: Unable to get provider FileProvider: SecurityException: Provider must grant uri permissions
我尝试向我的应用程序添加免安装应用程序功能,但在将我的应用程序作为免安装应用程序启动时出现此错误:
RuntimeException: Unable to get provider android.support.v4.content.FileProvider: java.lang.SecurityException: Provider must grant uri permissions
这是它在我的 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)
看起来像FileProvider
isn't supported on O either because other apps aren't allowed to see its ContentProvider
。
我有一个测试应用程序可以作为 已安装 应用程序使用,但不能作为 instant app。看起来 instant apps 不允许使用 grantUriPermission
(授予 URI 权限)(考虑到不能使用 instant apps 的政策,这是有道理的对已安装的应用程序可见,ContentProvider
不可见)。
这意味着免安装应用无法检索使用 ACTION_IMAGE_CAPTURE
拍摄的照片(因为它们无法读取外部存储并且相机应用无法写入免安装应用的私有存储)。
<provider
android:exported="false"
android:grantUriPermissions="true"
android:authorities="${applicationId}.fileprovider"
android:name="androidx.core.content.FileProvider">
<meta-data
android:resource="@xml/file_paths"
android:name="android.support.FILE_PROVIDER_PATHS"
/>
</provider>
我尝试向我的应用程序添加免安装应用程序功能,但在将我的应用程序作为免安装应用程序启动时出现此错误:
RuntimeException: Unable to get provider android.support.v4.content.FileProvider: java.lang.SecurityException: Provider must grant uri permissions
这是它在我的 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)
看起来像FileProvider
isn't supported on O either because other apps aren't allowed to see its ContentProvider
。
我有一个测试应用程序可以作为 已安装 应用程序使用,但不能作为 instant app。看起来 instant apps 不允许使用 grantUriPermission
(授予 URI 权限)(考虑到不能使用 instant apps 的政策,这是有道理的对已安装的应用程序可见,ContentProvider
不可见)。
这意味着免安装应用无法检索使用 ACTION_IMAGE_CAPTURE
拍摄的照片(因为它们无法读取外部存储并且相机应用无法写入免安装应用的私有存储)。
<provider
android:exported="false"
android:grantUriPermissions="true"
android:authorities="${applicationId}.fileprovider"
android:name="androidx.core.content.FileProvider">
<meta-data
android:resource="@xml/file_paths"
android:name="android.support.FILE_PROVIDER_PATHS"
/>
</provider>