0

I'm trying to make a app, that takes information of some sort, then i want it to email that information to my gmail. I have found working code but when i load it onto my phone and run it and got all the info loaded into the app,and click the email, from what i understand its suppose to filter apps(on my phone) that are capable to send the email but I'm not getting anything, even though i have the default Email app that comes on the phone and i have Gmail.

public void Done(View view) {
   Intent email = new Intent(Intent.ACTION_SENDTO); // it's not ACTION_SEND
    email.putExtra(Intent.EXTRA_EMAIL, "some@gmail.com");
    email.putExtra(Intent.EXTRA_SUBJECT, "OverStock Changes");
    email.putExtra(Intent.EXTRA_TEXT, printReport());
    email.setType("message/rfc822");
    startActivity(Intent.createChooser(email, "Email"));

}

1 Answers1

0

See answer for ACTION_SENDTO for sending an email

If you use ACTION_SENDTO, putExtra() does not work to add subject and text to the intent. Use setData() and the Uri tool add subject and text.

This example works for me:

// ACTION_SENDTO filters for email apps (discard bluetooth and others)
String uriText =
    "mailto:youremail@gmail.com" + 
    "?subject=" + URLEncoder.encode("some subject text here") + 
    "&body=" + URLEncoder.encode("some text here");

Uri uri = Uri.parse(uriText);

Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
sendIntent.setData(uri);
startActivity(Intent.createChooser(sendIntent, "Send email")); 

Otherwise use ACTION_SEND as mentioned:

intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"mail@mail.com","mail2@mail.com"});
intent.putExtra(Intent.EXTRA_SUBJECT,"subject");
intent.putExtra(Intent.EXTRA_TEXT, "mail content");
startActivity(Intent.createChooser(intent, "title of dialog")); 
Community
  • 1
  • 1
JRomero
  • 4,878
  • 1
  • 27
  • 49
  • adding subjecct/text isnt my problem, its startActivity(Intent.createChooser(sendIntent, "Send email")); thats suppose to give me apps that have email cababilities but im not getting any says none were found – user1547386 Jun 18 '13 at 18:49
  • I don't see a setData in your code, ACTION_SENDTO uses data instead of Extras. Try adding the uri since it might be related to it missing. Don't forget the crucial part `mailto:` – JRomero Jun 18 '13 at 18:57