下面是html代码。我想要打开电子邮件并填写"到#34;字段与" someone@gmail.com"
<a href="mailto:someone@gmail.com">Send Mail</a>
我已经尝试过这段代码了,它打开了电子邮件,但仍然是&#34;到#34;字段为空
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("tel:")) {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
startActivity(intent);
return true;
} else if (url.startsWith("mailto:")) {
String mail = url.replace("mailto:", "");
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, mail );
startActivity(Intent.createChooser(intent, "Send Email"));
return true;
} else {
return false;
}
}
我的代码出了什么问题,谢谢
答案 0 :(得分:0)
这就是我使用MailTo
类:
MailTo mailTo = MailTo.parse(url);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{mailTo.getTo()});
intent.putExtra(Intent.EXTRA_TEXT, mailTo.getBody());
intent.putExtra(Intent.EXTRA_SUBJECT, mailTo.getSubject());
intent.putExtra(Intent.EXTRA_CC, mailTo.getCc());
intent.setType("message/rfc822");
startActivity(intent);