Android webview 遇到android.os.FileUriExposedException錯誤解決辦法
1. 在 Manifest 文件中添加:
<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> 2. 創建 XML 文件: res/xml/provider_paths.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>
3. 把獲取文件URI代碼替換成新的api:
... imageUri = Uri.fromFile(createImageFile()); replace with : File file = createImageFile(); imageUri = FileProvider.getUriForFile(mActivity, mActivity.getPackageName() + ".provider", file); ...
如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答