1

i would like to send an image using android implicit intents.So my code is

Uri imageUri = Uri.parse("android.resource://com.example.intenttest/drawble/"+R.drawable.che3);
intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/*");
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Image Sending");
intent.putExtra(android.content.Intent.EXTRA_TEXT, "I AM ATTACHED THIS IMAGE");
intent.putExtra(Intent.EXTRA_STREAM, imageUri);
chooser = Intent.createChooser(intent, "Send Image");
startActivity(chooser);

the name of the image is che3.gif which is in drawable folder.And i tried with png format also i read the stackoverflow questions this and this i followed the first one but of no use .And it gives the error like unable to determine the mime type.The below is the log cat

I/ActivityManager(  287): START u0 {act=android.intent.action.SEND typ=image/png flg=0x3000001 cmp=com.android.email/.activity.MessageCompose (has clip) (has extras)} from pid 2180
E/Email   (  749): Unable to determine MIME type for uri=android.resource://com.example.intenttest/drawble/2130837504
E/Email   (  749): java.lang.Error
E/Email   (  749):  at com.android.emailcommon.utility.AttachmentUtilities.inferMimeTypeForUri(AttachmentUtilities.java:251)
E/Email   (  749):  at com.android.email.activity.MessageCompose.loadAttachmentInfo(MessageCompose.java:1607)
E/Email   (  749):  at com.android.email.activity.MessageCompose.addAttachmentFromSendIntent(MessageCompose.java:1674)
E/Email   (  749):  at com.android.email.activity.MessageCompose.initFromIntent(MessageCompose.java:2028)

So can any one please help me

Community
  • 1
  • 1
prasad
  • 1,277
  • 2
  • 16
  • 39
  • You can not attach image from private access into intent to expose with another app. – Pankaj Kumar Feb 18 '14 at 12:44
  • possible duplicate of [image attachment to a mail.. how in android?](http://stackoverflow.com/questions/2518055/image-attachment-to-a-mail-how-in-android) – Phantômaxx Feb 18 '14 at 12:46
  • Thanks for giving me answer so can you please tell me how to give permissions to the image which is in the drawable folder.why because i add the below line intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); [which i get from here](http://stackoverflow.com/questions/2518055/image-attachment-to-a-mail-how-in-android) but of no use – prasad Feb 19 '14 at 17:34

1 Answers1

2

This does not work because:

  • You cannot access a resource of one application in another
  • You cannot send a drawable when your MIME is "image".

You'll have to write the image to a publicly accessible Bitmap file and pass a path to that, or implement a ContentProvider.

FD_
  • 12,947
  • 4
  • 35
  • 62