我正在尝试从我的 Galaxy Note 3 平板电脑发送一封带有附件的邮件。我发送邮件的代码如下所示:
public static void sendMail(Context context, String rc, String subject, String message, File file, String type) {
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[] { rc });
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, message);
Uri uri = Uri.fromFile(file);
email.putExtra("android.intent.extra.MIME_TYPES", type);
// email.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
email.setClassName("com.android.email", "com.android.email.activity.MessageCompose");
email.putExtra(Intent.EXTRA_STREAM, uri);
context.startActivity(email);
}
文件保存到外置sdcard。如果我使用 Gmail 应用程序,附件已附加,我可以发送邮件。如果我使用来自 android 的股票电子邮件应用程序,则附件未附加,我不知道为什么。
有人知道为什么会这样吗?我发现了很多问题,如何将文件附加到电子邮件,他们几乎都使用这种附加文件的方式。那么为什么它只适用于 gmail 应用程序呢?
最佳答案
我以前遇到过类似的问题,但是使用这段代码我可以发送一封带有 csv 文件作为附件的电子邮件,使用“myMail”作为客户端。
Uri exportFile = null;
exportFile = Uri.fromFile(file);
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "testSubject");
emailIntent.putExtra(Intent.EXTRA_STREAM, exportFile);
String aEmailList[] = { "test@test.org" };
emailIntent.putExtra(Intent.EXTRA_EMAIL, aEmailList);
emailIntent.setType("message/rfc822");
emailIntent.putExtra(
Intent.EXTRA_TEXT,
emailText
);
startActivityForResult(emailIntent, REQUESTCODE_SENTEMAIL);
关于android - 发送带附件的邮件只适用于 GMail,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22456204/