1

I've searched Google for this, but have only found similar examples--not exactly what I need. I simply need to start messaging (SMS) and email intents from my app with their "to" fields already populated. So I need to send a number with the sms intent and an email address with the email intent. Any help would be appreciated.

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
oliverwhite
  • 563
  • 1
  • 8
  • 16

2 Answers2

2

For the e-mail part :

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {"foo@bar.com"});

emailIntent.setType("text/plain");
startActivity(Intent.createChooser(emailIntent, "Send a mail ..."));
fedj
  • 3,452
  • 1
  • 22
  • 21
  • 1
    You might also take a look to Intent.EXTRA_SUBJECT and Intent.EXTRA_TEXT to fill the e-mail – fedj Aug 10 '10 at 21:28
  • Thanks for the helpful responses. I noticed one thing though--when doing the SMS intent, setType() shouldn't be used because it will make the app chooser say that no apps can perform the action. – oliverwhite Aug 13 '10 at 05:51
  • Yep, setType is used to know if you want to send through E-mail, facebook, twitter, ... – fedj Aug 13 '10 at 11:18
  • To clarify: The receivers look at the setType() value and will present themselves in the chooser dialog if they decide they can handle the specified type. For example, on my device setType("text/html") prevents SMS apps from being an option, but setType("text/plain") does not. – NightWatchman Jan 06 '12 at 20:14
1

from Only Email apps to resolve an Intent

   String recepientEmail = ""; // either set to destination email or leave empty
   Intent intent = new Intent(Intent.ACTION_SENDTO);
   intent.setData(Uri.parse("mailto:" + recepientEmail));
   startActivity(intent);

will filter out all non-email applications.

Community
  • 1
  • 1
kanitw
  • 874
  • 10
  • 19