Android ERR_UNKNOWN_URL_SCHEME
程序员文章站
2022-03-12 07:51:13
笔者在Android WebView中拉起App报错ERR_UNKNOWN_URL_SCHEME错误原因很简单,WebView默认只支持https http 等协议,并不支持AndroidManifet中定义的这个scheme协议。如下是我原代码WebViewClient mWebviewclient = new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(...
笔者在Android WebView中拉起App报错ERR_UNKNOWN_URL_SCHEME
错误原因很简单,WebView默认只支持https http 等协议,并不支持AndroidManifet中定义的这个scheme协议。如下是我原代码
WebViewClient mWebviewclient = new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//返回true代表在当前webview中打开,返回false表示打开浏览器
view.loadUrl(url);
return true;
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
// TODO Auto-generated method stub
super.onReceivedError(view, errorCode, description, failingUrl);
}
};
webView.setWebViewClient(mWebviewclient);
调整shouldOverrideUrlLoading代码段,当遇到我定义的scheme协议时,通过Intent的方式打开即可
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//return super.shouldOverrideUrlLoading(view, url);
if (url.startsWith("http:")||url.startsWith("https:")||url.startsWith("ftp")){
view.loadUrl(url);
return true;
}
else if (url.startsWith("scheme://")){
Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
return false;
}
本文地址:https://blog.csdn.net/iningwei/article/details/108586570