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

问题描述:

之前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
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值