解决Android WebView中出现 Not allowed to load local resource:

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

     在Android WebView中如果想要在html中加载本地资源,那肯定会碰到Not allowed to load local resource问题,可以通过重写WebViewClient的shouldInterceptRequest方法来解决,首先修改加载本地资源的路径为http://localpath/realFilepath,在shouldInterceptRequest里面拿到http://localpath/realFilepath的资源,去掉http://localpath头,然后通过realFilepath读取本地文件,返回自己构造的WebResourceResponse就可以了。

转载于:https://my.oschina.net/fengcunhan/blog/746416

你可能感兴趣的:(解决Android WebView中出现 Not allowed to load local resource:)