Attaching an drawable image to email in android

2019-07-04 03:22发布

问题:

I have a list of Drawable images in my application and want to send one of the images through mail. my code looks like

Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("image/*");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Picture");                       
sendIntent.putExtra(Intent.EXTRA_STREAM,
                    Uri.parse(lstPhotos.get(newPosition).getPhotoURL()));
myActivity.startActivity(Intent.createChooser(sendIntent, "Email:"));

But in the above code i have a problem since i cannot get the image URI from the list of drawables. Can anyone help me how to send the image because if i use the above code i am getting an empty image of 0kb sent.

回答1:

You can do it by saving that image to a temporary location on internal/external cache directory as an image and then use that image's path in the attachment using Uri.