简体   繁体   English

Android:如何将可绘制资源附加到电子邮件?

[英]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. 您不能将URI发送到您自己的应用程序资源。 The application receiving this Intent isn't allowed to access this file. 收到此Intent的应用程序不允许访问此文件。

Try placing this file on your sdcard en send that location as Intent.EXTRA_STREAM 尝试将此文件放在您的SD卡上,然后将该位置作为Intent.EXTRA_STREAM发送

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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