When I click a link which goes to mailto:admin@ikiyuzoniki.net I get this error:
net: ERR_UNKNOWN_URL_SCHEME
I tried to add an <
This error is appeared because the WebView can’t recognize the URL Scheme,for example, the WebView will usually recognize http and https, anything other than these, for example – intent://,market://,app://,mail:// etc will not be recognized by webview unless we add a handler to handle these url schemes or by disabling these schemes and only load http and https schemes.
Here is an example to fix the common intent url scheme.
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return loadUrl(view, url);
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description,String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
//Log.d("Web Request Error", "");
showError(errorCode);
}
@TargetApi(Build.VERSION_CODES.M)
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
Log.d("WebResource error", "");
int errorCode = error.getErrorCode();
showError(errorCode);
}
});
private boolean loadUrl(WebView view, String url) {
if (url.startsWith("http:") || url.startsWith("https:")) {
view.loadUrl(url);
return false;
}
// Otherwise allow the OS to handle it
else if (url.startsWith("tel:")) {
Intent tel = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
startActivity(tel);
return true;
} else if (url.toLowerCase().startsWith("mailto:")) {
MailTo mt = MailTo.parse(url);
Intent emailIntent = newEmailIntent(mt.getTo(), mt.getSubject(), mt.getBody(), mt.getCc());
startActivity(emailIntent);
return true;
}
return true;
}
try this
if(url.startsWith("mailto:")){
MailTo mt = MailTo.parse(url);
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL, new String[]{mt.getTo()});
i.putExtra(Intent.EXTRA_SUBJECT, mt.getSubject());
i.putExtra(Intent.EXTRA_CC, mt.getCc());
i.putExtra(Intent.EXTRA_TEXT, mt.getBody());
mContext.startActivity(i);
view.reload();
return true;
}