博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
假设拦截WebView的错误和OS升级到4.4后链接不能点击的问题
阅读量:5329 次
发布时间:2019-06-14

本文共 3424 字,大约阅读时间需要 11 分钟。

android OS升级到4.4之后,有些WebView的链接我们点击无效了,以下能够解决当中的某一种情况:

webviewClient的shouldOverrideUrlLoading方法必须返回false,返回true会导致这个问题

有时候PM会有一种需求,假设不是Server那边的问题,那么想在界面上显示自己定义的错误(如遇到连接到WIFI CMCC而没有移动的password,手机显示着连接上了WIFI)

这时我们须要去截获WebView的error,能够通过重载setWebViewClient的方法去截获,能够參考google文档:

在代码:

			this.mWebView.setWebViewClient(new WebViewClient() {			public boolean shouldOverrideUrlLoading(WebView view, String url) {				if (url.startsWith(ReportActivity.this.getString(R.string.url_start_chars1)) 						|| url.startsWith(ReportActivity.this.getString(R.string.url_start_chars2))) {					view.loadUrl(url);				} else if(url.startsWith(ReportActivity.this.getString(R.string.url_start_chars3))){				    Uri uri=Uri.parse(url);			        Intent emailIntent=new Intent(Intent.ACTION_SENDTO, uri);			        List
availableSoft = getPackageManager().queryIntentActivities(emailIntent, PackageManager.MATCH_DEFAULT_ONLY); if (availableSoft.size() > 0) { try { startActivity(emailIntent); } catch (Exception e) { } } } return false; } @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { handler.proceed(); } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { //这里截获错误 isLoadingError = true; Toast.makeText(ReportActivity.this, "errorCode="+errorCode, Toast.LENGTH_LONG).show(); super.onReceivedError(view, errorCode, description, failingUrl); } }); this.mWebView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { if (newProgress >= 80) { updateState(true); System.out.println("=========isSuccess onProgressChanged isLoadingError="+isLoadingError); if(isLoadingError) { mState = State.GetDataError; } updateStateView(); } } });
错误的类型有:

// These ints must match up to the hidden values in EventHandler.    /** Generic error */    public static final int ERROR_UNKNOWN = -1;    /** Server or proxy hostname lookup failed */    public static final int ERROR_HOST_LOOKUP = -2;    /** Unsupported authentication scheme (not basic or digest) */    public static final int ERROR_UNSUPPORTED_AUTH_SCHEME = -3;    /** User authentication failed on server */    public static final int ERROR_AUTHENTICATION = -4;    /** User authentication failed on proxy */    public static final int ERROR_PROXY_AUTHENTICATION = -5;    /** Failed to connect to the server */    public static final int ERROR_CONNECT = -6;    /** Failed to read or write to the server */    public static final int ERROR_IO = -7;    /** Connection timed out */    public static final int ERROR_TIMEOUT = -8;    /** Too many redirects */    public static final int ERROR_REDIRECT_LOOP = -9;    /** Unsupported URI scheme */    public static final int ERROR_UNSUPPORTED_SCHEME = -10;    /** Failed to perform SSL handshake */    public static final int ERROR_FAILED_SSL_HANDSHAKE = -11;    /** Malformed URL */    public static final int ERROR_BAD_URL = -12;    /** Generic file error */    public static final int ERROR_FILE = -13;    /** File not found */    public static final int ERROR_FILE_NOT_FOUND = -14;    /** Too many requests during this load */    public static final int ERROR_TOO_MANY_REQUESTS = -15;

转载于:https://www.cnblogs.com/zfyouxi/p/4251346.html

你可能感兴趣的文章
二十一、加载静态文件,父模板的继承和扩展
查看>>
Spring Security (一)
查看>>
BZOJ 1798:
查看>>
码农视角 - Angular 框架起步
查看>>
url类
查看>>
Java虚拟机结构(一)
查看>>
第一节20181109 《Linux就该这么学》
查看>>
字符串倒序
查看>>
NKOJ-1437 校长杯 ---赛程编制
查看>>
elasticsearch
查看>>
js 页面定时刷新
查看>>
win7 jenkins 修改主目录
查看>>
Git学习笔记--日常基本使用
查看>>
nuget使用
查看>>
关于一类最小割图的建法
查看>>
Django---自定义admin组件思维导图
查看>>
输入一个链表,反转链表后,输出链表的所有元素。
查看>>
转如何用九条命令在一分钟内检查Linux服务器性能?
查看>>
win7下 go语言开发环境搭建(64bit)
查看>>
JavaScript权威指南--客户端存储
查看>>