【发布时间】:2017-05-05 04:50:39
【问题描述】:
我正在使用freshdesk 的hotline.io。作为 SDK 集成的一部分,我需要包含 FileProvider 以支持 Android 7.0+。问题是,我已经在清单中定义了 FileProvider。
<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>
<!-- provider_path.xml -->
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>
这是来自hotline.io SDK 文档的 FileProvider:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="my.app.demo.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/hotline_file_provider_paths" />
</provider>
<!-- hotline_file_provider_paths -->
<?xml version="1.0" encoding="utf-8"?>
<string name="hotline_file_provider_authority">my.app.demo.provider</string>
如果两个 FileProvider 都在 manifest.xml 中定义,显然会出错。有没有办法将两种资源都包含在一个提供者中?我尝试过像这样组合两种资源:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>
<string name="hotline_file_provider_authority">my.app.demo.provider</string>
</resources>
还有这个:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
<!-- I extract FileProvider.xml from the hotline.sdk and combine with local fileprovder.xml -->
<files-path
name="int_files"
path="." />
<external-files-path
name="ext_files"
path="." />
<cache-path
name="int_cache"
path="." />
<external-cache-path
name="ext_cache"
path="." />
</paths>
但无济于事。我仍然收到此错误。
“Hotline 的 FileProvider 缺失/错误。在运行 Nougat 或更高版本操作系统的设备中,摄像头捕获将失败(错误代码 354)”
已修复
感谢greenapps 指出我。我错误地配置了 FileProvider。通过将 <string name="hotline_file_provider_authority">my.app.demo.provider</string> 移动到 strings.xml 来解决它。
【问题讨论】:
-
<string name="hotline_file_provider_authority">my.app.demo.provider</string>错误。这不是来自 hotline_file_provider_paths.xml 而是来自 strings.xml。从您提供的链接中查看文档。 -
只要 android:authorities 和 android:resource 不同,您的应用程序中就可以有尽可能多的 FileProfider。我什至认为 android:resource 可以指向同一个 xml 文件。他们不是显示了一个示例 hotline_file_provider_paths.xml 文件吗?
-
我也有同样的问题。 @greenapps - 我在清单中添加了两个具有不同资源和权限的提供者。但我收到错误:AndroidManifest.xml:339:9-347:20 的元素 provider#android.support.v4.content.FileProvider 与 AndroidManifest.xml 中声明的元素重复
-
@amad-yus ,您能否为您组合的文件提供程序发布完整的 android manifect 和 file_path.xml。我需要在我的项目中实施。这将是很大的帮助。谢谢。
标签: android android-manifest android-fileprovider