通过Android的Gmail应用程序发送PNG附件 [英] Sending PNG attachment via Android GMail app

查看:118
本文介绍了通过Android的Gmail应用程序发送PNG附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我附上一个PNG图像的电子邮件具有以下code:

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)));

本机HTC的电子邮件应用程序对付这个不错,但Gmail应用硬要给附件一.JPG扩展名,即使影像,绝对是一个PNG。这可能只是在Gmail应用程序中的错误,但我认为我会问反正。

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.

这是什么样的logcat显示了当附件被附:

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

是否有某种方式来控制所使用的Gmail应用程序的文件名?我找不到任何明显的意图演员文档。理想情况下,我会能够指定的全名,但即使只得到它使用正确的文件扩展名是一个胜利。

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.

推荐答案

也许Gmail应用假定由媒体商店的应用程序提供的内容始终是JPG格式的图片。它甚至可能是媒体商店可能提供了错误的数据传送到Gmail应用程序。

Maybe the GMail app assumes that content delivered by the media store app are always jpg pictures. It might even be the Media store which could provide wrong data to the GMail app.

您可以尝试存储上的文件系统,并作为Gmail的不完全支持文件中的PNG文件://尤里斯(它只能与外部存储的文件),你可以使用自定义的ContentProvider简单地提供从内容与内容的文件:// URI来代替。你可以找到这样的内容提供商<一href="http://$c$c.google.com/p/openintents/source/browse/trunk/filemanager/FileManager/src/org/openintents/filemanager/FileManagerProvider.java"相对=nofollow>这里。

You could try to store your PNG file on the file system and as the GMail doesn't fully support file:// Uris (it works only with files on external storage) you may use a custom ContentProvider to simply provide content from a file with a content:// uri instead. You can find such a content provider here.

另外一个简单的测试,可能是通过Gmail使用像EStrongs或天文文件资源管理器应用程序发送的文件系统中的PNG文件。如果Gmail仍然会强制.JPG扩展,那么你可能会很难找到一个办法来解决这个左右。

One other simple test could be to send a PNG file from the filesystem through GMail using a File explorer app like EStrongs or Astro. If GMail still forces the .jpg extension then you may have hard time finding a way to work this around.

最后的想法,请尝试使用一个更通用的MIME类型类似的应用程序/八位字节流(而这可能会导致问题的邮件接收邮件应用程序可能不知道它是什么类型的文件)

Last idea, try using a more generic mime-type like application/octet-stream (but this could lead to problems for in mail receivers mail applications which might not understand what kind of file it is)

这篇关于通过Android的Gmail应用程序发送PNG附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆