0

I am trying to start an activity in my main activity. I am trying to send data via email. But when i run the code my program crash . here is my code of starting new activity

Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("plain/html");
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"aaa@gmail.com","ssss@yahoo.com"});
    intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
    intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("my html text goes here"));
    startActivity(intent);
Diptopol Dam
  • 823
  • 1
  • 10
  • 39
  • 1
    Hi see [this](http://www.anddev.org/email_send_intent_intentchooser-t3295.html) – Adil Soomro Apr 08 '11 at 06:48
  • [2011-04-08 12:53:13 - second_project] Installing second_project.apk... [2011-04-08 12:53:24 - second_project] Success! [2011-04-08 12:53:24 - second_project] Starting activity com.second_project.geo_loc on device emulator-5554 – Diptopol Dam Apr 08 '11 at 06:54
  • The log trace is in LogCat, not Console. – Patrick Apr 08 '11 at 07:10
  • @ Adil Soomro in the last line of the code what he mean by intent?? He is using emailIntent right?? – Diptopol Dam Apr 08 '11 at 07:14

1 Answers1

1

Try using Intent.createChooser method to find an application that should send your mail, like this:

    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.setType(EMAIL_CONTENT_TYPE);

    emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {"aaa@gmail.com","ssss@yahoo.com"});
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "subject");
    emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("my html text goes here"));

    Intent chooser = Intent.createChooser(emailIntent, "Choose the application to send the email");
    startActivity(chooser);
Flavio
  • 6,205
  • 4
  • 30
  • 28
  • @ Flavio I tried your approach . But it still not working . My program is still running but nothing happens .How can i know that message is gone?? – Diptopol Dam Apr 08 '11 at 11:36
  • This way you pass your message to mail application like gmail. And using gmail you message will be sent! So...you should register an account in gmail or in other mail programm. And only after that Intent.createChooser will find all mail programms and propose you to choose one to send the message. – Flavio Apr 08 '11 at 12:09
  • 1
    If you want to send the message directly without help of android mail programs you should use java mail API. – Flavio Apr 08 '11 at 12:10
  • finally problem was solved . use this [link](http://stackoverflow.com/questions/2020088/sending-email-in-android-using-javamail-api-without-using-the-default-android-app) – Diptopol Dam Apr 16 '11 at 04:02