我尝试像这样设置 anchor 标记 mailto 属性
<a href='mailto:info@company.com'>info@company.com</a>
在 WebView 中。当我在模拟器上运行该应用程序并单击它显示“不支持的操作 ..”的链接时
我如何在 android webview 中设置 mailto 属性....
谢谢
最佳答案
WebView 不支持高级 HTML 标签...您需要做的是:
- 为您的 webview 设置一个 webclient 并覆盖 url 加载
- 当您检测到带有
mailto
的链接时,请尝试发送电子邮件。
我会给你一小段代码,让你有一个想法。请记住,这只是一个基本示例,我现在无法对其进行测试:
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 - 如何设置 anchor 标记mailto : attribute in webview, android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3197430/