简体   繁体   中英

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, "foo@bar.com");
    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?

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

使用CWAC-Provider,以便您可以传递指向您资源的内容URI。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM