4

I have a requirement that I need to attach a ".zip" file and send the email using Gmail Service.

I am using below code to do this:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType(application/x-compressed);
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{abc@gmail.com});
intent.putExtra(Intent.EXTRA_STREAM,         
Uri.parse(abc.zip);
intent.putExtra(Intent.EXTRA_TEXT, "hello..");

If I use the "application/x-compressed" mime type , I am able to send ".zip" attachments but I am unable launch Gmail composer directly, before that it is providing list of options.

If I use "message/rfc822" mime type, I am able to launch Gmail composer directly, but unable to attach ".zip" files.

Pl. help me to how to combine these two mime types in a single intent object. Pl. let me know if there's any alternative to do this. thanks.

ferostar
  • 7,074
  • 7
  • 38
  • 61
brig
  • 3,721
  • 12
  • 43
  • 61

3 Answers3

1

This worked for me -

intent.setType("application/zip, application/octet-stream, application/x-zip-compressed, multipart/x-zip")

Mime type found in this answer

vepzfe
  • 4,217
  • 5
  • 26
  • 46
-1

intent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");

to open Gmail directly. however if gmail is not installed it will cause exception, ActivityNotFound

Happy Dev
  • 573
  • 10
  • 17
-2

I am using this code and works. check this:

Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{"Example@gmail.com"});        
email.putExtra(Intent.EXTRA_SUBJECT, "subject//@@");
email.putExtra(Intent.EXTRA_TEXT, "message//@@");
email.setType("message/rfc822");
Uri uri = Uri.parse("sdcard/1.zip");
email.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(email, "Choose an Email client :")); 
FarZad
  • 94
  • 8