Webview中可以设置的几种缓存比较:

WebviewClient
WebCromeClient常用办法:
1、shouldOverrideUrlLoading(WebView view, String url)
在API 24今后过时,当一个url即将被webview加载时,给Application一个机会来接收处理这个url,办法返回true代表Application本身处理url;返回false代表Webview处理url。
举个例子,项目中须要处理传过来的URL是一个事宜照样一个HTTP链接,可以经由过程自定义协定头 (nativeapi://) 来过滤,如:
- @Override
- public boolean shouldOverrideUrlLoading(WebView view, String url) {
- Uri uri = Uri.parse(url);
- String scheme = uri.getScheme();
- if (TextUtils.isEmpty(scheme)) return true;
- if (scheme.equals("nativeapi")) {
- //如定义nativeapi://showImg是用来查看大年夜图,这里添加查看大年夜图逻辑
- return true;
- } else if (scheme.equals("http") || scheme.equals("https")) {
- //处理http协定
- if (Uri.parse(url).getHost().equals("www.example.com")) {
- // 内部网址,不拦截,用本身的webview加载
- return false;
- } else {
- //跳转外部浏览器
- Intent intent = new Intent(Intent.ACTION_VIEW, uri);
- context.startActivity(intent);
推荐阅读
【技巧沙龙】AI开辟者拭魅战营-7分钟打造1个定制技能。7月22号,我们等你一路! 国度卫计委长途医疗治理与培训中间办公室主任卢清君(中国台湾网 尹赛楠 摄)2017年(第九届>>>详细阅读
本文标题:Android Webview使用和遇到过的坑总结
地址:http://www.17bianji.com/lsqh/36219.html
1/2 1

网友点评
精彩导读
科技快报
品牌展示