I use the following code in order to share an image :
Uri imguri=Uri.parse("android.resource://PackageName/drawable/"+ R.drawable.img);
Intent intent=new Intent(Intent.ACTION_SEND);
intent.setType("image/png");
intent.putExtra(Intent.EXTRA_STREAM,imguri);
Intent ch=Intent.createChooser(intent,"Send image");
startActivity(ch);
The file is sent (for instance using GMAIL) but the problem is that there is no extension. It is simply named 2130837559.
Is there a way to get the real name (img) and the extension (png) ?
Partly, that is up to the email client, not you.
Partly, that is because your code does not send the real name or the extension. R.drawable.img
is an int
, quite possibly 2130837559
in decimal. If you look at your Uri
that you are sending, you will not see the filename or the file extension.
Your only hope for getting Gmail to think in terms of your filename and extension will be to have a Uri
that has those values in it. Solutions include:
Copying the resource to a file on external storage and using a file://
Uri
(not recommended)
Copying the resource to a file on internal storage and using FileProvider
to give you a content://
Uri
Using my StreamProvider
to serve the value straight out of raw resources, and setting up the name
to give your resulting Uri
a filename and extension (note: this would require you to have the PNG file as a raw resource, rather than as a drawable resource)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With