简体   繁体   中英

How to attach an image from SD Card to an email?

I am trying to attach an image from SD Card to an email (from my app to Gmail app).

Every time I try, I select Gmail app and it closes, it doesn't attach the file.

Let's say the image path is: /sdcard/DCIM/Snapseed/Snapseed4.jpg . This is the code I am using to send the email:

Intent emailintent2 = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailintent2.setType("image/*");
emailintent2.putExtra(Intent.EXTRA_EMAIL, emailaddress2);
emailintent2.putExtra(Intent.EXTRA_SUBJECT, CorAsunto);
emailintent2.putExtra(Intent.EXTRA_TEXT, message2);

Uri uris = Uri.fromFile(new File(Environment.getExternalStorageDirectory()
        + "/DCIM/Snapseed/Snapseed4.jpg"));

emailintent2.putExtra(Intent.EXTRA_STREAM, uris);
startActivity(emailintent2);
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.setType("text/plain");
    emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    emailIntent.setType("image/jpeg");
    emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("SDCARD IMAGE PATH"));
    startActivity(Intent.createChooser(emailIntent,"Share image using"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM