spacitron
spacitron

Reputation: 2183

Android: how to attach a resource drawable to an email?

I'm trying to send an image drawable as an email attachment using the following code:

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_SUBJECT, "[email protected]");
    intent.putExtra(Intent.EXTRA_TEXT, "Lorem ipsum...");
    intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://"+ getPackageName() + R.drawable.ic_launcher));
    startActivity(intent);

However I am given a message that the file does not exist. What am I missing here?

Upvotes: 0

Views: 648

Answers (2)

zmarties
zmarties

Reputation: 4869

Use CWAC-Provider so that you can pass a content URI that points at your resources.

Upvotes: 0

Ion Aalbers
Ion Aalbers

Reputation: 8030

You cannot send an URI to your own application resources. The application receiving this Intent isn't allowed to access this file.

Try placing this file on your sdcard en send that location as Intent.EXTRA_STREAM

Upvotes: 1

Related Questions