目的是为了提高加载速度。比如jquery可以预先放置在app assets。把远程页面中的/sss/jquery.js文件在发起请求前映射到本地android_asset/jquery.js文件。
在ios中我可以用 LocalSubstitutionCache.mappingDict 做到。在android中一直找不到解决方案。
前提是不能修改远程页面的代码,不能在远程页面中使用“file:///android_asset”之类的资源路径。
走同样的路,发现不同的人生
WebView provides a callback from API 11 to handle similar requirements. i.e. shouldInterceptRequest
public WebResourceResponse shouldInterceptRequest(WebView view, String url) { Log.i(LOGTAG, "shouldInterceptRequest url=" + url + ";threadInfo" + Thread.currentThread()); WebResourceResponse response = null; if (url.contains("logo")) { try { InputStream localCopy = getAssets().open("droidyue.png"); response = new WebResourceResponse("image/png", "UTF-8", localCopy); } catch (IOException e) { e.printStackTrace(); } } return response; }
For details, please refer to this article. WebView in Android intercepts and replaces network request data
How do you load the files in the assets directory in your webview page? ? ?
WebView provides a callback from API 11 to handle similar requirements. i.e. shouldInterceptRequest
For details, please refer to this article. WebView in Android intercepts and replaces network request data
How do you load the files in the assets directory in your webview page? ? ?