未设置MIME类型为电子邮件附件:Android的 [英] Android: mime type for email attachment not set

查看:115
本文介绍了未设置MIME类型为电子邮件附件:Android的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个很小的应用程序为Android 2.3.3。 我想发送电子邮件(通过Android电子邮件应用程序),包含JPEG图片作为附件,以下relevat code(仅测试与SDK模拟器):

I'm developing a very small application for Android 2.3.3. I want to send an email (through the android email app) containing a jpeg image as an attachment, below the relevat code (tested only with sdk emulator):

public void sendArtwork(View aView){
        EditText subj = (EditText)findViewById(R.id.edit_subj);
        EditText descr = (EditText)findViewById(R.id.edit_descr);
        Intent emailIntent = new Intent(Intent.ACTION_SEND);
        emailIntent.setType("image/jpeg");  // attachment is a jpeg
        emailIntent.putExtra(Intent.EXTRA_EMAIL,new String[]{"contribute@unintentional.org"}); 
        emailIntent.putExtra(Intent.EXTRA_SUBJECT,subj.getText().toString()); //get subject from one EditText in the UI
        emailIntent.putExtra(Intent.EXTRA_TEXT,descr.getText().toString()); //get body from one EditText in the UI
        emailIntent.putExtra(Intent.EXTRA_STREAM, fileURI); // add attachment
        startActivityForResult(Intent.createChooser(emailIntent, "Choose Email application:"), EMAIL_CODE);

    }

它按预期工作:它会打开一个选择器,创建一个具有正确的地址,主题,正文和附件的电子邮件,并将其发送。

It works as expected: it opens a Chooser, creates an email with the correct address, subject, text and attachment and sends it.

我不能够做到的唯一的事情就是设置正确的MIME类型的图像:附件被正确接收(我可以将其分离到磁盘上,然后打开它),但没有内容类型,因此电子邮件客户端(雷鸟)不显示preVIEW并不能提供一个应用程序将其打开。 是否有人对此有意见吗?

The only thing I'm not able to accomplish is to set the correct mime type for the image: the attachment is received correctly (i can detach it to disk and open it) but without a content type, so the email client (Thunderbird) does not display a preview and is not able to provide an application to open it. Does anybody have advice on this?

---- 修改

图片文件发送各地没有任何错误:如说,如果我将它保存在磁盘上的我的电脑上,并使用合适的应用程序(例如Picasa中),它正确地显示了其打开。

The image file is sent across without any errors: as said, if I save it on disk on my PC and open it using a suitable application (i.e. Picasa) it shows up correctly.

推荐答案

我用同样的方法来发送电子邮件,并在各种版本的一些电子邮件客户端进行测试。 即使Gmail是inconsitent,有些版本设置附件的MIME类型,其他人忽略它。 我得出的结论是没有安全的解决方案。至少不通过使用ACTION_SEND意图

I'm using the same method for sending emails, and have tested on various versions of a few email clients. Even gmail is inconsitent, some versions sets the mime type of the attachment, others ignore it. I've came to the conclusion that there is no safe solution. At least not by using an ACTION_SEND Intent.

这篇关于未设置MIME类型为电子邮件附件:Android的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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