From my application, I am trying to create an email containing an image contained in a raster object.
private void sendEmailWithBitmapAttached(){ final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("plain/text"); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Email Subject"); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Email Body"); emailIntent.setType("image/png"); ContentResolver cr = getContentResolver();
This works fine in Android 2.3.
But using later versions, it causes the following error:
07-13 23:01:01.252: E/MediaStore(5194): Failed to insert image 07-13 23:01:01.252: E/MediaStore(5194): java.lang.SecurityException: Permission Denial: writing com.android.providers.media.MediaProvider uri content://media/external/images/media from pid=5194, uid=10151 requires android.permission.WRITE_EXTERNAL_STORAGE, or grantUriPermission()
So, accepting the error suggestion, I tried to provide a UriPermission.
grantUriPermission(String toPackage, Uri uri, int modeFlags)
But I'm not sure what to put for toPackage or uri
But then again, using the error message, I changed the code as follows:
private void sendEmailWithBitmapAttached(){ final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("plain/text"); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Email Subject"); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Email Body"); emailIntent.setType("image/png"); ContentResolver cr = getContentResolver();
And I get the same error.
Can a gracious soul please give me a hint how to take care of saving uri and provider resources? Is this the right approach?
Thank you very much for ANY help, hint, recommendations or suggestions you can provide!