我正在尝试使用意图在安卓设备中发送文件。我启动了一个意图选择器并选择了GMail应用程序。问题是,我无法设置自定义的MIME类型,它总是变成application/octet-stream。
在较旧版本的GMail应用程序(或者可能是较旧版本的Android,如JB之前的版本?)中,做法是可以正常工作的:
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)));
有人知道如何设置MIME类型以适应GMail / Android的较新版本吗?
经过一些尝试和错误,我发现在GMail应用程序版本4中,这很正常,但在GMail版本4.2中无法设置MIME类型或以另一种方式完成。 有人知道怎么做吗? :/