admin管理员组文章数量:1794759
Android 11 WebView 打开html文件,加载时报错:ERR
问题描述:
之前andorid 10上做的需求,移植到Android 11上
在项目中,system/app/HTMLViewer/ 自定义的加载html的xxxActivity.java文件访问 手机系统中的
/system/etc/ *.html 文件时, 加载时报错:ERR_ACCESS_DENIED
原因分析:Android 11 上面 WebSettings.setAllowFileAccess(boolean allow) 方法说明:
The default value is {@code true} for apps targeting *
{@linkandroid.os.Build.VERSION_CODES#Q} and below,
and {@code false} when targeting
* {@link android.os.Build.VERSION_CODES##R} and above.
1. 在Android 10及以下版本,这个值默认是为true的, android 11 以上默认为false。
Enables or disables file access within WebView. * Note that this enables or disables file system access only. Assets and resources are still accessible using file:///android_asset and file:///android_res.
2. 在 WebView 中启用或禁用文件访问。请注意,这仅启用或禁用文件系统访问。 assert 和 res 仍然可以使用 file:///android_asset 和 file:///android_res 访问。
3. android 11 上面google出于安全考虑,不推荐用webview直接访问文件,如果实际项目中有需要,就需要设置为true
解决方案:
WebSettings.setAllowFileAccess(true)
版权声明:本文标题:Android 11 WebView 打开html文件,加载时报错:ERR 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1686959407a122354.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论