Azam
Azam

Reputation: 1

how can I use internal resource (e.g. R.id.myImage01) as an email attachment?

how can I use internal resource (e.g. R.drawable.myImage01) as an email attachment? I tried the following code. It shows the file is attach but actually the email gets send without any attachment.

Context context = getApplicationContext();   
String imagePath = context.getFilesDir() + "/" + "myImage01.png";
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse(imagePath));

Thanks Azam

Upvotes: 0

Views: 452

Answers (2)

Josh Lee
Josh Lee

Reputation: 177675

The other option would be a content provider. Use a URL like

"content://com.example.myapp/images/" + R.drawable.myImage01

and then use the provided ID to stream the content to the client.

(That is, I assume that this will work.)

Upvotes: 1

Cristian
Cristian

Reputation: 200140

As it's an internal resource, the email client won't be able to access to that file. Thus, you have to copy the image to the SDCard, and then attach that file.

Upvotes: 1

Related Questions