Custom mime type ignored in GMail app

谁说我不能喝 提交于 2019-12-07 12:05:32

问题


I'm trying to send a file in android using intents. I fire up an intent chooser and select the GMail app. The problem is that I can't set my custom mime type, it always becomes application/octet-stream.

In older versions of the GMail app (or maybe older versions of Android, like pre-JB?) it worked fine doing like this:

Intent sendIntent = new Intent(Intent.ACTION_SEND);
// Add attributes to the intent
sendIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Send my file");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(path));
sendIntent.setType("application/vnd.mycustommimetype");
context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.lblShare)));

Anyone know how to set the mime type to work with later versions of GMail/Android?

After som trial and error have I seen that in GMail app version 4 this works just fine, but in GMail version 4.2 it's not possible to set mime type or it's done in another way. Anyone knows how? :/


回答1:


Unfortunately, there is not much you can do. Some email apps, for god knows what reason, incorrectly set the mime type for custom files, to octet-stream. Your best shot is to set your custom mime type, but then, on the receiving end, make sure you also accept octet-stream. Then, you will need to check the file extension to make sure it is indeed your file, and not something else, not intended for your app (I am assuming you are also using a custom extension).




回答2:


please check this code snippet

final Intent emailIntent = new Intent(Intent.ACTION_SEND); 
emailIntent.setType("text/plain"); 
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"webmaster@website.com"}); 
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "my subject"); 
emailIntent.putExtra(Intent.EXTRA_TEXT, "body text"); 
context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));


来源:https://stackoverflow.com/questions/13870570/custom-mime-type-ignored-in-gmail-app

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