Take the 2-minute tour ×

i am trying to programmatically attach an image to an email body from my app .I've seen some topics about how to do that and put my code exactly the same way but it's useless i don't get the image in the other side (from this post ) . for more information here is my code:

Intent emailIntent=new Intent(Intent.ACTION_SEND);
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.mail_partage_objet));
            emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(readEmailTemplate()));
            String imageFilePath=Constants.PHOTO_CACHE_PATH+"/"+currentPlace.getPhotoFileName();
            Log.d(TAG,"Picture Path: "+imageFilePath);
            emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(imageFilePath));
            startActivity(Intent.createChooser(emailIntent, getResources().getString(R.string.email_share)));

where PHOTO_CACHE_PATH is the path of directory where the image is saved and it's on SDcard

share|improve this question
Hi Houcine, i'm no Android developer but a few things to consider, is the image attached and not viewable on the email or not attached at all? What happens if you try and save the file you are attaching as a new filename, can you view this new filename ok? –  Neo Jan 27 '12 at 14:27
@Neo : you should ask the person who has posted the question , not me :) , i've just edited the question to organize the code ^^ –  Houcine Jan 27 '12 at 14:38
@Houcine LOL yeah I should but it was easier to type your name in than user748677 it makes them sound like a statistical figure ;) –  Neo Jan 27 '12 at 14:47
@Neo : yes that's it , it is a member but he doesn't specify a pseudoname for his account ,that's why the website stackoverflow affect the user xxxxx in function of the number of unregistred users ( like visiters ) ;) –  Houcine Jan 27 '12 at 15:18

1 Answer 1

up vote 0 down vote accepted

I think you forgot: emailIntent.setType("application/octet-stream");.

Example for multiattachments:

    Intent exportMessageIntent = new Intent(
    ArrayList<Uri> uris = new ArrayList<Uri>();

            //array of urls to your files on device - they are strings
    filePaths = new String[] { "path1","path2" };  //for your case just insert imageFilePath -> filePaths = new String[] { imageFilePath };
            //create files from string array of paths
    for (String file : filePaths) {
        File fileIn = new File(file);
        Uri u = Uri.fromFile(fileIn);

            .putExtra(Intent.ACTION_DEFAULT, "test/");

    exportMessageIntent.putExtra(Intent.EXTRA_SUBJECT,"Subject text");



Hope it helps, Toni

share|improve this answer
Toni, he has set the mimetype to a jpeg image instead of octet-stream –  Neo Jan 27 '12 at 16:29
Yes Neo, I didn't saw that. But I'll leave the working example if somebody needs it. Maybe user748677 regarding your first comment Neo. I thing he should see the attachment if he share it by mail (before he sends the mail). I agree with Neo. –  toni Jan 30 '12 at 6:28

Your Answer


