我的应用程序创建带附件的邮件,并使用意图Intent.ACTION_SEND来启动邮件应用程序.
它适用于我测试过的所有邮件应用,除了新的Gmail 5.0(适用于Gmail 4.9),邮件打开时没有附件,显示错误:"附件权限被拒绝".
在logcat上没有来自Gmail的有用消息.我只测试了Android KitKat上的Gmail 5.0,但是在多个设备上.
我为附件创建了这样的文件:
String fileName = "file-name_something_like_this";
FileOutputStream output = context.openFileOutput(
fileName, Context.MODE_WORLD_READABLE);
// Write data to output...
output.close();
File fileToSend = new File(context.getFilesDir(), fileName);
Run Code Online (Sandbox Code Playgroud)
我知道安全问题MODE_WORLD_READABLE.
我发送这样的意图:
public static void compose(
Context context,
String address,
String subject,
String body,
File attachment) {
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("message/rfc822");
emailIntent.putExtra(
Intent.EXTRA_EMAIL, new String[] { address });
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, body);
emailIntent.putExtra(
Intent.EXTRA_STREAM,
Uri.fromFile(attachment));
Intent chooser = Intent.createChooser(
emailIntent,
context.getString(R.string.send_mail_chooser));
context.startActivity(chooser);
}
Run Code Online (Sandbox Code Playgroud)
在创建文件或发送意图时,我有什么问题吗?有没有更好的方法来启动带附件的邮件应用程序?或者 …