which mime type to use ,to attach ".zip" file in Gmail
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开发者_Python百科 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.
This worked for me -
intent.setType("application/zip, application/octet-stream, application/x-zip-compressed, multipart/x-zip")
Mime type found in this answer
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
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 :"));
精彩评论