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

编程知识 更新时间:2023-04-06 10:49:58

问题描述:

之前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_ACCESS_DENIED

本文发布于:2023-04-06 10:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/30b0160483497ec8c4655057a5f0d32a.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时报   加载   文件   Android   WebView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 49143文章数
  • 14阅读数
  • 0评论数