由网友(癡人說夢i)分享简介:我写为Android应用程序。我怎样才能从它发送电子邮件?I am writing an application for Android. How can I send an email from it?推荐答案最好的(和最简单的)方法是使用一个意图:The best (and easiest) way is...
我写为Android应用程序。我怎样才能从它发送电子邮件?
I am writing an application for Android. How can I send an email from it?
推荐答案
最好的(和最简单的)方法是使用一个意图
:
The best (and easiest) way is to use an Intent
:
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
否则,你就必须编写自己的客户端。
Otherwise you'll have to write your own client.
相关推荐
最新文章