It is assumed that what you want to load in WebView
is a url, in this case the error message indicates that what you are trying to load is not valid, the schema is not an url, maybe you are trying to open other schemes or even custom schemes:
mark:
todolist:
abc:
mailito:
telefonito:
myshcheme:
richard:
as an example if we use the telefonito:
scheme, inside your page that loads in WebView
,
<a href="telefonito:123-555-5555">Call me now!</a>
When clicking, this scheme is not related to an action, you will get the error message:
The webpage at ............. could not be loaded because
net :: ERR_UNKNOWN_URL_SCHEME
however if you use the http:
scheme that represents a url, clicking will work without problem.
<a href="http://es.stackoverflow.com">Abrir stackoverflow!</a>
The default supported schemes are http:
, https:
, tel:
, mailto:
and even market://
in an android device to load in WebView
.
What the code does within shouldOverrideUrlLoading()
is only allow to load content within WebView
the urls that start with http:
and https:
, any other scheme will handle it with a Intent
, in this case I recommend you also validate that you can only perform the intent for tel:
and mailto:
, since in other cases it can also cause an error (for example telefonito:
):
mWebView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if( url.startsWith("http:") || url.startsWith("https:") ) {
return false;
}
//Agregar validación para email y telefono.
if( url.startsWith("tel:") || url.startsWith("mailto:") ) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}
return true;
}
});