Launch Gmail to send a mail coupled with an attachment

你说的曾经没有我的故事 提交于 2019-12-04 15:46:55

问题


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.


回答1:


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);
}

Or

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);
}


来源:https://stackoverflow.com/questions/7148475/launch-gmail-to-send-a-mail-coupled-with-an-attachment

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