启动Gmail发送再加一个带有附件的邮件再加、附件、邮件、Gmail

2023-09-05 05:05:27 作者:浪荡成性

在我的应用程序,用户有机会导出和导入自己的数据文件,我想也增加通过邮件发送此数据文件作为附件的选项。 我怎样才能做到这一点? 感谢您的帮助。

In my application, the user have the opportunity to export and import his data file, and i want to add also the option to send this data file by mail as attachment. How can i do this? Thank you for your help.

推荐答案

我的code到了图片附件发送电子邮件:

My code to send email with a image attachment:

public void sendViaEmail(String pAttachmentPath, String pSubjectLine) {
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, pSubjectLine);
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, 
            "Screenshot ****************");
    emailIntent.setType("image/jpeg");
    emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile("file://" + pAttachmentPath));
    mActivity.startActivity(emailIntent);
}

public void sendViaEmail(File pAttachmentFile, String pSubjectLine) {
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, pSubjectLine);
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, 
            "Screenshot ****************");
    emailIntent.setType("image/jpeg");
    emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(pAttachmentFile));
    mActivity.startActivity(emailIntent);
}