如何发送在Android 2.2的电子邮件? [英] How to send an email in android 2.2?
问题描述
我要与Android 2.2发送电子邮件。首先,我做了意向选择器与ACTION_SEND选择要使用的:
I want to send an email with android 2.2. First I made an intent chooser with an ACTION_SEND to select which to use :
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, Resources.getString("EmailInvitationSubject", getBaseContext()));
String body = Resources.getString("EmailInvitationBody", getBaseContext()) + Local.User.FirstName;
intent.putExtra(Intent.EXTRA_TEXT, body);
startActivity(Intent.createChooser(intent, "Invite friends"));
但在这种情况下,选择显示蓝牙消息,Google +和Gmail的。我想只显示Gmail或其他电子邮件应用程序。
But in that case, the selector show 'Bluetooth, Messaging, Google+, Gmail'. I want to show ONLY Gmail or other email app.
我在SDK文档看到有一个新的CATEGORY_APP_EMAIL使用,但它只是在API层面15.我必须保持API级别8可有没有办法做到这一点?
I saw in the sdk docs there's a new CATEGORY_APP_EMAIL to use but it's only available in the API level 15. I have to keep API level 8. Is there a way to do that ?
顺便说一句,我想这样做的太消息,这样我到底可以有2个按钮:一个用于电子邮件和一个用于通讯
By the way, I'll want to do it for messaging too so that in the end I can have 2 buttons: one for email and one for messaging.
推荐答案
这code将只显示电子邮件客户端,
This code will shows only the email clients,
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{"youremail@yahoo.com"});
email.putExtra(Intent.EXTRA_SUBJECT, "subject");
email.putExtra(Intent.EXTRA_TEXT, "message");
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email client :"));
这篇关于如何发送在Android 2.2的电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!