0

I want to send email on the gmail account. When i use this it prompts a dialog which asks to select type like facebook, gmail, yahooo...

Before this i am using intent chooser now i am using just intent in the following code. It calls intent chooser for the first time.. but i want default selection is gmail account

Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("image/jpeg");
        intent.setType("application/octet-stream");
        intent.putExtra(Intent.EXTRA_EMAIL, emailAddressList);
        intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
        intent.putExtra(Intent.EXTRA_TEXT, emailText);
        intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+image_id));
        startActivity(intent);
Jaffar Raza
  • 301
  • 1
  • 4
  • 19

2 Answers2

1

Try changing the intent.setType("image/jpeg") and intent.setType("application/octet-stream") to the following:

intent.setType("plain/text"); 

Hope it helps.

sabadow
  • 4,994
  • 2
  • 32
  • 50
  • i want to send image to... Is plain text will work with plain text too. – Jaffar Raza Mar 06 '12 at 11:59
  • I know that you want to sent the image too, but the pain/text MIME is only checked by gmail app so maybe adds the image through the EXTRA_STREAM param. Have you tried it? – sabadow Mar 06 '12 at 12:03
  • But i am getting image from the resource and when i write this intent.setType("plain/text") than i cant able to get the extension.. If i want to get the image extension than i have to write intent.setType("image/jpeg") – Jaffar Raza Mar 06 '12 at 12:11
  • Yes i tried it it works but the file extension not append with the image file and the email received in attachment is not an image. – Jaffar Raza Mar 06 '12 at 12:20
1

I don't think it is possible to use Gmail as default client from application without user intervention.

If you really want this to happen, you will have to find some other alternative which is nothing but Java Mail Api. See this question which elaborates more on this.

Also read following articles to get more insights on this:

  1. Sending email without Intent.createChooser
  2. How to use JavaMail API in android to send mail from any email Account?
Community
  • 1
  • 1
AndroDev
  • 3,006
  • 6
  • 32
  • 48