我正在使用 Firebase 的构建变体,我的应用程序还需要使用 FileProvider 来共享要在 3rd 方应用程序中打开的应用程序文件。但是,当我尝试在 Intent 中发送 URI 时,应用程序崩溃并出现以下错误。
error:java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/Android/data/com.example.debug/files/Pictures/JPEG_20170919_113955_102027655.jpg
这是我的配置
String authority = getString(R.string.authority_provider);
Uri fileUri = FileProvider.getUriForFile(context, authority, file);
将文件提供程序添加到 AndroidManifest.xml 中的应用程序标签内:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="@string/authority_provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
file_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="my_images" path="Android/data/${applicationId}/files/Pictures" />
<external-file-path name="my_images" path="Android/data/${applicationId}/files/Pictures" />
</paths>
由于Firebase
要求使用 2 个应用程序 ID 来保存崩溃日志,Firebase 控制台中的分析是分开的
字符串:authority_provider - 添加到 build.gradle(app) 中:
buildTypes {
release {
---
applicationIdSuffix "com.example"
resValue "string", …