如何设置锚标记至mailto:属性在web视图,机器人 [英] how to set anchor tag mailto: attribute in webview, android
本文介绍了如何设置锚标记至mailto:属性在web视图,机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图设置锚标记的mailto属性像
I tried to set anchor tag mailto attribute like
<a href='mailto:info@company.com'>info@company.com</a>
在web视图。当我运行模拟器上的应用程序,并单击它显示链接不支持的行动。
in webview. when i run the app on simulator and click on the link it is showing "Unsupported Action .."
如何设置的mailto属性在Android的WebView中摸出....
How i can set mailto attribute work out in android webview....
感谢
推荐答案
的WebView不支持高级HTML标签......你将要做的是:
WebView does not support advanced HTML tags... what you will have to do is:
- 设置一个Web客户机到您的WebView并重写URL加载
- 当你发现与
的mailto
的链接尝试发送电子邮件。
- Set a webclient to your webview and override the url loading
- When you detect a link with
mailto
try to send the email.
我会给你code的小片段让你有一个想法。请记住,这仅仅是一个基本的例子,现在我不能测试它:
I'm gonna give you a little snippet of code for you to have an idea. Keep in mind this is just a basic example and I can't test it right now:
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;
}
}
然后,发送电子邮件:
Then, send the email:
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...));
}
这篇关于如何设置锚标记至mailto:属性在web视图,机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文