android 拦截h5方法,android - webview 拦截资源的几个方法和特点

android - webview 拦截资源的几个方法和特点

2017-08-12 18:27

访问量: 2060

分类:

技术

看下面的代码,就可以看出端倪来了

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/BTC-blue@3x.png

shouldInterceptRequest, 触发的url是====http://yunbih5.sweetysoft.com/static/images/ETH-blue@3x.png

shouldInterceptRequest, 触发的url是====http://yunbih5.sweetysoft.com/static/images/DGD-blue@3x.png

shouldInterceptRequest, 触发的url是====http://yunbih5.sweetysoft.com/static/images/SC-blue@3x.png

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);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值