When I click a link which goes to mailto:[email protected] I get this error:
net: ERR_UNKNOWN_URL_SCHEME
I tried to add an if(url.startsWith("mailto:"))
condition but it's not working.
This is my MyWebViewClient
method:
public class MyWebViewClient extends WebViewClient {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
}
@Override
public void onPageFinished(WebView view, String url) {
view.setVisibility(View.VISIBLE);
final Animation fade = new AlphaAnimation(0.0f, 1.0f);
fade.setDuration(200);
view.startAnimation(fade);
view.setVisibility(View.VISIBLE);
}
}
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.startsWith("mailto:")){
Intent intent = null;
try {
intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
} catch (URISyntaxException e) {
e.printStackTrace();
}
view.getContext().startActivity(intent);
}
else if (url.endsWith(".mp3")) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), "audio/*");
startActivity(intent);
} else if (url.endsWith(".mp4") || url.endsWith(".3gp")) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), "video/*");
startActivity(intent);
}
else {
return false;
}
view.reload();
return true;
}
and this is how I add the function to my web view before loadUrl
:
...
mWebview.setWebViewClient(new MyWebViewClient());
...
intent.setType("message/rfc822");
. Also see https://mcmap.net/q/404544/-handling-links-in-a-webview – Encomium