如何在WebView,Android中设置锚定标记mailto:属性
作者:互联网
我试图将锚标记的mailto属性设置为
<a href='mailto:info@company.com'>info@company.com</a>
在网络视图中.当我在模拟器上运行该应用程序并单击链接时,它显示“不支持的操作..”
我如何在Android Webview中设置mailto属性…
谢谢
解决方法:
WebView不支持高级HTML标记…您需要做的是:
>将webclient设置为您的webview并覆盖url加载
>当您检测到邮件链接时,尝试发送电子邮件.
我要给您一些代码片段,让您有个想法.请记住,这只是一个基本示例,我现在无法对其进行测试:
public void onCreate(Bundle icicle) {
// blablabla
WebView webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient( new YourWebClient());
// blablabla
}
private class YourWebClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.contains("mailto")) {
// TODO: extract the email... that's your work, LOL
String email = "";
sendEmail();
return super.shouldOverrideUrlLoading(view, url);
}
view.loadUrl(url);
return true;
}
}
然后,发送电子邮件:
public void sendEmail(String email){
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{email});
String mySubject = "this is just if you want";
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, mySubject);
String myBodyText = "this is just if you want";
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, myBodyText);
context.startActivity(Intent.createChooser(intent, "Send mail...));
}
标签:android-emulator,android-widget,android 来源: https://codeday.me/bug/20191209/2097964.html