小弟最近在做項目時發現一個很奇怪的錯誤,打開word文檔調用第三方應用時老時出錯,經過研究發現了他報這個錯誤
image.png
上網搜了一下 再加下自己的整理,終于明白還是權限的問題,現把解決方案貼上
1.清單文件中添加provider
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="wjx.bhne.com.tbsopenoffice.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"/>
</provider>
image.png
標紅位置為包名,各位同時改成自己的就行
2.創建清單文件中的@xml/file_paths文件
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="office" path="."/>
</paths>
3.更改URI獲取方法
Uri uri = Uri.fromFile(file);
上面是原來獲取方式
Uri uri = FileProvider.getUriForFile(OpenFileActivity.this, "wjx.bhne.com.tbsopenoffice.fileprovider", file);
更改后便好了!!! 如果你感覺有用的話就點個喜歡吧!!