mobiledev Alex
mobiledev Alex

Reputation: 2318

send image from ImageView as email attachment

How can I know filename of ImageView image? I want to send it as email attachment.

UPDATE: I don't use images from resources. I have images from android storage(as in contacts app) using:

new Intent(Intent.ACTION_GET_CONTENT, null);

and from camera. Camera is OK - I can get filepath. But storage is question

Upvotes: 1

Views: 3464

Answers (2)

Kenny
Kenny

Reputation: 5542

If the image is a resource that you provide then you can get the path to the image. The format is:

"android.resource://[package]/[res id]"

[package] is your package name

[res id] is value of the resource ID, e.g. R.drawable.example

You can then pass this as an extra in your create e-mail intent like this:

Intent sendIntent = new Intent(Intent.ACTION_SEND);
//Mime type of the attachment (or) u can use sendIntent.setType("*/*")
sendIntent.setType("image/jpeg");
//Subject for the message or Email
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "My Picture");
//Full Path to the attachment
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://your.package.name/" + R.drawable.example));
//Use a chooser to decide whether email or mms
startActivity(Intent.createChooser(sendIntent, "Email:"));

Upvotes: 3

Dan S
Dan S

Reputation: 9189

The short answer is that you can't, as images can be from a variety of sources. What you can do is get the bitmap cache with the same result of sending the image.

Upvotes: 1

Related Questions