irpas技术客

Android 11 WebView 打开html文件,加载时报错:ERR_ACCESS_DENIED_broadview_java_android err_a

网络 7591

问题描述:

之前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)?? ?


1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。

标签: #Android #11 #webview