Android Webview ERR_UNKNOWN_URL_SCHEME错误
作者:互联网
当我点击链接到mailto:admin@ikiyuzoniki.net时,我收到此错误:
net: ERR_UNKNOWN_URL_SCHEME
我试图添加一个if(url.startsWith(“mailto:”))条件,但它不起作用.
这是我的MyWebViewClient方法:
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;
}
这就是我在loadUrl之前将该函数添加到我的Web视图的方法:
...
mWebview.setWebViewClient(new MyWebViewClient());
...
解决方法:
试试这个
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;
}
标签:android,mailto 来源: https://codeday.me/bug/20190612/1222890.html