将图片从相机和图库附加到电子邮件

时间:2016-11-02 05:02:28

标签: java android

如何将捕获/存储的图像作为附件附加到电子邮件中?

从相机捕获图像的代码,

capture image from camera code

从图库中检索图片的代码,

image from gallery

1 个答案:

答案 0 :(得分:0)

使用可以简单地使用隐式Intent来附加图像,

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