which mime type to use ,to attach “.zip” file in Gmail

匿名 (未验证) 提交于 2019-12-03 07:36:14

问题:

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.

回答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



回答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 :"));  


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!