附加在电子邮件中的图像未收到 [英] Image attached in email is not received

查看:222
本文介绍了附加在电子邮件中的图像未收到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图以编程方式将图像从我的应用程序.I've看到有关如何做到这一点,把我的code完全相同的方式有些话题附加到电子邮件的身体,但我不明白的也没用在另一边(从这个帖子)图像。
有关更多信息,这里是我的code:

 意图emailIntent =新意图(Intent.ACTION_SEND);
            emailIntent.setData(Uri.parse(电子邮件地址:));
            emailIntent.setType(图像/ JPG);
            emailIntent.putExtra(Intent.EXTRA_SUBJECT,getResources()的getString(R.string.mail_partage_objet));
            emailIntent.putExtra(Intent.EXTRA_TEXT,Html.fromHtml(readEmailTemplate()));
            串imageFilePath = Constants.PHOTO_CACHE_PATH +/+ currentPlace.getPhotoFileName();
            Log.d(TAG,图片路径:+ 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))。);

其中P​​HOTO_CACHE_PATH是图像保存目录的路径,它是在SD卡


解决方案

我想你忘记了: emailIntent.setType(应用程序/八位字节流); <。 / p>

举例multiattachments:

 意图exportMessageIntent =新意图(
            android.content.Intent.ACTION_SEND_MULTIPLE);
    exportMessageIntent.setType(text / plain的);
    exportMessageIntent.setType(应用程序/八位字节流);
    ArrayList的&LT;&乌里GT;的URI =新的ArrayList&LT;&乌里GT;();            // URL到您的文件在设备上的阵列 - 他们是字符串
    文件路径=新的String [] {路径1,路径2}; //你的情况下,只需插入imageFilePath - &GT;文件路径=新的String [] {} imageFilePath;
            //创建路径字符串数组文件
    对于(字符串的文件:文件路径){
        文件FILEIN =新的文件(文件);
        乌里U = Uri.fromFile(FILEIN);
        uris.add(U);
    }
    exportMessageIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,
            的URI);    exportMessageIntent
            .putExtra(Intent.ACTION_DEFAULT,测试/);    exportMessageIntent.putExtra(Intent.EXTRA_SUBJECT主题文字);    exportMessageIntent.putExtra(Intent.EXTRA_TEXTbodyText的);    startActivity(exportMessageIntent);

希望它能帮助,
托尼

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

解决方案

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

这篇关于附加在电子邮件中的图像未收到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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