android - webview 拦截资源的几个方法和特点
访问量: 2858
看下面的代码,就可以看出端倪来了
onPageStarted, 触发的url是====http://yunbih5.sweetysoft.com/#/bindAccountToDevice?client=android&language=en shouldInterceptRequest, 触发的url是====http://app.yun.com/v1/markets shouldInterceptRequest, 触发的url是====http://yunbih5.sweetysoft.com/static/img/pattern-diamond.c4ea2db.png shouldInterceptRequest, 触发的url是====http://yunbih5.sweetysoft.com/#/bindAccountToDevice?client=android&language=en shouldInterceptRequest, 触发的url是====http://yunbih5.sweetysoft.com/static/images/[email protected] shouldInterceptRequest, 触发的url是====http://yunbih5.sweetysoft.com/static/images/[email protected] shouldInterceptRequest, 触发的url是====http://yunbih5.sweetysoft.com/static/images/[email protected] shouldInterceptRequest, 触发的url是====http://yunbih5.sweetysoft.com/static/images/[email protected] shouldInterceptRequest, 触发的url是====http://yunbih5.sweetysoft.com/#/xxxDevice?client=android&language=en shouldInterceptRequest, 触发的url是====http://yunbih5.sweetysoft.com/#/xxxDevice?client=android&language=en
public class MyWebViewClient extends WebViewClient { // 在上面log中没有看到, 貌似也是可以拦截的..... 需要进一步搜集日志 @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Log.d(TAG, "shouldOverrideUrlLoading, 触发的url是====" + url); //FIXME 姜瑶确认下,这里是否有用. // view.loadUrl(appendParameters(url)); return false; } /** * 触发的都是基本的URL页面(无法拦截vuejs内的跳转) */ @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { Log.d(TAG, "onPageStarted, 触发的url是====" + url); super.onPageStarted(view, url, favicon); } 拦截到的, 是所有的URL(除了 正常的Url 还包括图片,js, css) @Override public WebResourceResponse shouldInterceptRequest(WebView view, String url) { Log.d(TAG, "shouldInterceptRequest, 触发的url是====" + url); if(url.contains("__webpack_hmr")) { Log.d(TAG, "return empty response on __webpack_hmr"); return new WebResourceResponse(null,null, null); }