I'm attaching a PNG image to an e-mail with the following code:
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, title);
values.put(MediaStore.Images.Media.DESCRIPTION, title);
values.put(MediaStore.Images.Media.MIME_TYPE, "image/png");
Uri uri = activity.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
OutputStream stream = activity.getContentResolver().openOutputStream(uri);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
stream.close();
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/png");
intent.putExtra(Intent.EXTRA_SUBJECT, "Message title");
intent.putExtra(Intent.EXTRA_TEXT, "Message body");
intent.putExtra(Intent.EXTRA_STREAM, uri);
activity.startActivity(Intent.createChooser(intent, activity.getString(R.string.share)));
The native HTC e-mail app copes with this fine but the GMail app insists on giving the attachment a ".jpg" extension even though the image is definitely a PNG. This may just be a bug in the GMail app but I thought I'd ask anyway.
This is what logcat shows when the attachment is attached:
I/Gmail ( 285): >>>>> Attachment uri: content://media/external/images/media/11
I/Gmail ( 285): >>>>> type: image/png
I/Gmail ( 285): >>>>> name: 1287752711300.jpg
I/Gmail ( 285): >>>>> size: 0
Is there some way to control the file name used by the GMail app? I couldn't find anything obvious in the Intent extras documentation. Ideally I would be able to specify the full name, but even just getting it to use the right file extension would be a victory.