Android: mime type for email attachment not set

怎甘沉沦 提交于 2019-12-01 04:17:20

问题


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.

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?

----EDIT

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.


回答1:


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.



来源:https://stackoverflow.com/questions/10946203/android-mime-type-for-email-attachment-not-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!