How to send an email in android 2.2?

若如初见. 提交于 2020-01-15 10:57:05

问题


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

But in that case, the selector show 'Bluetooth, Messaging, Google+, Gmail'. I want to show ONLY Gmail or other email app.

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 ?

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.


回答1:


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



回答2:


You might want to checkout following (to get what you are looking at the end, i.e. "....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

or also you could checkout: Android email chooser

Kind regards,
Bo



来源:https://stackoverflow.com/questions/10614908/how-to-send-an-email-in-android-2-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!