我如何知道ImageView图像的文件名? 我想将其作为电子邮件附件发送。
更新:我不使用资源中的图片。我使用:
从Android存储(如联系人应用程序)中获取图像new Intent(Intent.ACTION_GET_CONTENT,null);
来自相机。相机没问题 - 我可以获得文件路径。但存储是个问题
答案 0 :(得分:3)
如果图像是您提供的资源,则可以获取图像的路径。格式为:
“android.resource:// [package] / [res id]”
[包]是您的包裹名称
[res id]是资源ID的值,例如R.drawable.example
然后,您可以在创建电子邮件意图中将此作为额外内容传递,如下所示:
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:"));
答案 1 :(得分:1)
简短的回答是你不能,因为图像可以来自各种来源。您可以做的是获得bitmap cache与发送图像相同的结果。