简体   繁体   English

如何在android 2.2中发送电子邮件?

[英]How to send an email in android 2.2?

I want to send an email with android 2.2. 我想发送一封带有android 2.2的电子邮件。 First I made an intent chooser with an ACTION_SEND to select which to use : 首先,我使用ACTION_SEND制作了一个意图选择器来选择使用哪个:

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"));

But in that case, the selector show 'Bluetooth, Messaging, Google+, Gmail'. 但在这种情况下,选择器会显示“蓝牙,信息,Google+,Gmail”。 I want to show ONLY Gmail or other email app. 我只想显示Gmail或其他电子邮件应用。

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 ? 我在sdk文档中看到有一个新的CATEGORY_APP_EMAIL可供使用,但它仅在API级别15中可用。我必须保持API级别8.有没有办法做到这一点?

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. 顺便说一下,我也想做消息传递,以便最终我可以有2个按钮:一个用于电子邮件,一个用于消息传递。

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 :"));

You might want to checkout following (to get what you are looking at the end, ie "....By the way, I'll want to do it for messaging too so that in the end I can have 2 buttons: "): http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_%28no_Intents%29_in_Android 您可能想要签出以下内容(以获得您最终看到的内容,即“....顺便说一句,我也希望将其用于消息传递,以便最终我可以拥有2个按钮:”) : http//www.jondev.net/articles/Sending_Emails_without_User_Intervention_%28no_Intents%29_in_Android

or also you could checkout: Android email chooser 或者你也可以结账: Android电子邮件选择器

Kind regards, 亲切的问候,
Bo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM