Image attached in email is not received

╄→尐↘猪︶ㄣ 提交于 2019-12-24 07:14:43

问题


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.setData(Uri.parse("mailto:"));
            emailIntent.setType("image/jpg");
            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.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            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


回答1:


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

Example for multiattachments:

    Intent exportMessageIntent = new Intent(
            android.content.Intent.ACTION_SEND_MULTIPLE);
    exportMessageIntent.setType("text/plain");
    exportMessageIntent.setType("application/octet-stream");
    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);
        uris.add(u);
    }
    exportMessageIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,
            uris);

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

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

    exportMessageIntent.putExtra(Intent.EXTRA_TEXT,"bodytext");

    startActivity(exportMessageIntent);

Hope it helps, Toni



来源:https://stackoverflow.com/questions/9034351/image-attached-in-email-is-not-received

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