我尝试将锚标记mailto属性设置为
<a href='mailto:info@company.com'>info@company.com</a>
在webview中。当我在模拟器上运行应用程序并单击链接时,它显示“不支持的操作..”
我如何设置mailto属性在android webview ....
谢谢
答案 0 :(得分:3)
WebView不支持高级HTML标记......您需要做的是:
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...));
}
答案 1 :(得分:0)
设为
myTemplate ="<a>info@company.com</a>";
或只是
myTemplate ="info@company.com";
并加载到WebView
mWebView.loadDataWithBaseURL(null, myTemplate, "text/html", "utf-8", null);
答案 2 :(得分:0)
这是克里斯蒂安答案的另一种选择。
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (!(url.startsWith("http") || url.startsWith("#"))) {
launchIntent(url);
return true;
}
view.loadUrl(url);
return true;
}
private void launchIntent(String url){
final Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
Uri uri = Uri.parse(url);
intent.setData(uri);
context.startActivity(intent);
}
这将允许锚标签,例如mailto:tel:和google.navigation:q = an + url + uncoded + address
如果您的html页面包含您不希望意图启动的其他锚点,则可能需要调整条件。