6

I had this in my onOptionItemSelected of menu. Whenever I try to run this intent it throws force close error.

case R.id.Mail:
    Intent emailIntent=new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.setType("plain/text");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,message);
    startActivity(emailIntent);
    break;
Razin
  • 181
  • 1
  • 13

4 Answers4

9

it might help you..

Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{"abc@gmail.com"});        
email.putExtra(Intent.EXTRA_SUBJECT, "Sunject Text Here..");
email.putExtra(Intent.EXTRA_TEXT, "");
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Send Mail Using :"));
Ajay
  • 1,189
  • 1
  • 12
  • 28
  • its show some dialog box saying:"No apllication can perform this action" – Razin Mar 22 '13 at 12:51
  • yes, it opens Email and Gmail and etc options. you can use default configured email account to send mail using this dialog box. and once this dialog will open, just select checkbox ( at bottom of that dialog ) to set this as default. then it will not open any dialog again. :) – Ajay Mar 22 '13 at 12:55
  • yeah this might work for me but can u tell me how can i setup E-Mail app in my emulator?? – Razin Mar 22 '13 at 12:58
  • Thanks its working. can u explain this "email.setType("message/rfc822");" and vote for my question. – Razin Mar 22 '13 at 14:17
  • ya sure, "email.setType("message/rfc822")" will set the SMTP/MIME type of this email intent. and a Content-Type "message/rfc822" indicates that the body contains an encapsulated message, with the syntax of an RFC 822 message. – Ajay Mar 23 '13 at 05:53
0

try to use it like that

        Intent intent = new Intent(); 
    intent.setAction(android.content.Intent.ACTION_SEND); 
    intent.setType("plain/text");
    intent.putExtra(android.content.Intent.EXTRA_EMAIL,  new String[]{address});
    return intent;
steevoo
  • 621
  • 6
  • 18
0

try this. emailIntent.setType("plain/text");

rahul
  • 6,447
  • 3
  • 31
  • 42
0

Your code is correct.May be you have to check that your email is register in you android mobile email application.You have to create one id in your mobile email application.

case R.id.Mail:
    Intent emailIntent=new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.setType("plain/text");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,message);
    startActivity(emailIntent);
    break;
Bhargav Panchal
  • 1,159
  • 1
  • 12
  • 27