我想在webview加载外部网页时,网页中需要的图片都从Android本地加载,应该如何实现呢?
我现在试了一种办法,如下:
网页上加载图片的代码如下:
<html>
<body background='file:///storage/emulated/0/bcitImg/img/bodybg.png'>
</body>
</html>
Android加载网页的代码如下:
pbWebView.loadUrl("http://*.*.*.*:8080/bcis/jsp/bcit/welcome.jsp");
运行时提示:
[INFO:CONSOLE(143)] "Not allowed to load local resource: file:///storage/emulated/0/bcitImg/img/footer.png", source: http://...:8080/bcis/jsp/bcit/welcome.jsp
是需要webview设置什么权限吗,还是我方法不对。webview加载Android本地的网页时,这种方式是可以的。
黄舟2017-04-17 17:11:14
webview.getSettings().setAllowFileAccess(true);
webview.getSettings().setAllowFileAccessFromFileURLs(true);
webview.getSettings().setAllowUniversalAccessFromFileURLs(true);
Please refer to these settings.
PHPz2017-04-17 17:11:14
Call native methods using JS support
webView.getSettings().setJavaScriptEnabled(true);
Call the local image in the local method and pass it to js, and then display it on the web page.
大家讲道理2017-04-17 17:11:14
You can refer to this article http://blog.csdn.net/qq122627... About some problems with webview loading local images