【错误记录】Android 文件分享 FileProvider 设置错误
【摘要】
文章目录
一、报错信息二、解决方案
一、报错信息
分享内部存储到文件到其它应用 ;
2021-05-18 16:10:23.480 31881-31881/kim...
一、报错信息
分享内部存储到文件到其它应用 ;
2021-05-18 16:10:23.480 31881-31881/kim.hsl.file E/DEBUG: --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
2021-05-18 16:10:23.480 31881-31881/kim.hsl.file E/DEBUG: Process Name: 'kim.hsl.file'
2021-05-18 16:10:23.480 31881-31881/kim.hsl.file E/DEBUG: Thread Name: 'main'
2021-05-18 16:10:23.480 31881-31881/kim.hsl.file E/DEBUG: Back traces starts.
2021-05-18 16:10:23.481 31881-31881/kim.hsl.file E/DEBUG: java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/kim.hsl.file/files/5.mp3
2021-05-18 16:10:23.481 31881-31881/kim.hsl.file E/DEBUG: at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:711)
2021-05-18 16:10:23.482 31881-31881/kim.hsl.file E/DEBUG: at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:400)
2021-05-18 16:10:23.482 31881-31881/kim.hsl.file E/DEBUG: at android.view.View.performClick(View.java:6597)
2021-05-18 16:10:23.482 31881-31881/kim.hsl.file E/DEBUG: at android.view.View.performClickInternal(View.java:6574)
2021-05-18 16:10:23.483 31881-31881/kim.hsl.file E/DEBUG: at android.view.View.access$3100(View.java:778)
2021-05-18 16:10:23.483 31881-31881/kim.hsl.file E/DEBUG: at android.view.View$PerformClick.run(View.java:25885)
2021-05-18 16:10:23.483 31881-31881/kim.hsl.file E/DEBUG: at android.os.Handler.handleCallback(Handler.java:873)
2021-05-18 16:10:23.484 31881-31881/kim.hsl.file E/DEBUG: at android.os.Handler.dispatchMessage(Handler.java:99)
2021-05-18 16:10:23.484 31881-31881/kim.hsl.file E/DEBUG: at android.os.Looper.loop(Looper.java:193)
2021-05-18 16:10:23.484 31881-31881/kim.hsl.file E/DEBUG: at android.app.ActivityThread.main(ActivityThread.java:6718)
2021-05-18 16:10:23.484 31881-31881/kim.hsl.file E/DEBUG: at java.lang.reflect.Method.invoke(Native Method)
2021-05-18 16:10:23.485 31881-31881/kim.hsl.file E/DEBUG: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
2021-05-18 16:10:23.485 31881-31881/kim.hsl.file E/DEBUG: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
2021-05-18 16:10:23.485 31881-31881/kim.hsl.file E/DEBUG: Back traces ends.
2021-05-18 16:10:23.485 31881-31881/kim.hsl.file E/DEBUG: --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
二、解决方案
配置 FileProvider ,
使用 androidx 支持库的情况 :
<manifest>
...
<application>
...
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.mydomain.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
...
</application>
</manifest>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
或 使用 support 支持库的情况 :
<manifest>
...
<application>
...
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.mydomain.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
...
</application>
</manifest>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
file_paths.xml 文件配置 : 下面的配置将所有的文件设置为可分享的文件 , 具体还要根据需求自己定制 ;
<paths
xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external" path="." />
<external-files-path name="external_files" path="." />
<cache-path name="cache" path="." />
<external-cache-path name="external_cache" path="." />
<files-path name="files" path="." />
</paths>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
文章来源: hanshuliang.blog.csdn.net,作者:韩曙亮,版权归原作者所有,如需转载,请联系作者。
原文链接:hanshuliang.blog.csdn.net/article/details/116994499
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)