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

眉间皱痕 提交于 2019-12-25 02:14:45

问题


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?


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/22537933/android-how-to-attach-a-resource-drawable-to-an-email

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!