简体   繁体   中英

Attaching picture from camera and gallery to email

How to attach a captured/stored image to email as an attachment?

Code for capturing image from camera,

capture image from camera code

Code for retrieving image from gallery,

image from gallery

Use can simply use an implicit Intent to attach the image,

   Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
   shareIntent.setType("image/jpeg");

   //set your subject
   shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Email Subject"); 
   //set your message    
   shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Email Messasge"); 

   String imagePath = "specify_the_image_path_here"

   File imageFileToShare = new File(imagePath);
   Uri uri = Uri.fromFile(imageFileToShare);

   shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
   startActivity(Intent.createChooser(shareIntent, "Share Image"));

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