Launch Gmail to send a mail coupled with an attachment

前端 未结 1 609
借酒劲吻你
借酒劲吻你 2021-02-11 03:20

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

相关标签:
1条回答
  • 2021-02-11 04:01

    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);
    }
    
    0 讨论(0)
提交回复
热议问题