您的位置:首页 > 移动开发

Android webview 遇到android.os.FileUriExposedException错误解决办法

2017-10-25 09:02 891 查看

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);
...

如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐