从节约和Android的SD卡中嵌入采摘电子邮件正文中的一个图像 [英] embed a image in email body from saving and picking in sdcard in android

查看:163
本文介绍了从节约和Android的SD卡中嵌入采摘电子邮件正文中的一个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过SD卡保存,然后从那个地方,但影像撷取嵌入在电子邮件正文中一个内嵌图像不被显示,公正的OBJ是there.Kindly显示帮助我,这里是$ C我的功能$ C:

  {    位图newImg = BitmapFactory.de codeByteArray的(IMG,0,img.length);    。字符串根= Environment.getExternalStorageDirectory()的toString();
    文件MYDIR =新的文件(根+/ saved_images);
    myDir.mkdirs();
    字符串FNAME =stoneage.jpg;
    档案文件=新的文件(MYDIR,FNAME);    尝试{
           FileOutputStream中出=新的FileOutputStream(文件);
           newImg.com preSS(Bitmap.Com pressFormat.JPEG,90出);
           了out.flush();
           out.close();    }赶上(例外五){
           e.printStackTrace();
    }    URI URI = NULL;
    URI = Uri.parse(文件://+ Environment.getExternalStorageDirectory()+/ saved_images /+ FNAME);
    串txtBody =下; HTML>&下;身体GT;&下; H1>喜是斯通奇产物所述; / H1>&所述峰; br>&下; IMG SRC =+ URI +/>&下; /身体GT;&下; / HTML&GT ;;
    Log.d(数据,txtBody);    意图emailIntent =新意图(android.content.Intent.ACTION_SEND);
    emailIntent.setType(text / html的);  emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECTtestemail子);
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,Html.fromHtml(txtBody));
    startActivity(Intent.createChooser(emailIntent,电子邮件:)); }


解决方案

试试这个来保存文件:

  {尝试
        myfile文件=新的文件(/ SD卡/ mysdfile.jpg);
        myFile.createNewFile();
        FileOutputStream中FOUT =新的FileOutputStream(MYFILE);
        OutputStreamWriter myOutWriter =
                                新OutputStreamWriter(FOUT);
        myOutWriter.append(txtData.getText());
        myOutWriter.close();
        fOut.close();
        Toast.makeText(getBaseContext(),
                写完SD'mysdfile.txt'
                Toast.LENGTH_SHORT).show();
    }赶上(例外五){
        Toast.makeText(getBaseContext(),e.​​getMessage(),
                Toast.LENGTH_SHORT).show();
    }    意图emailIntent =新意图(android.content.Intent.ACTION_SEND);
    emailIntent.setType(应用/图像);
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,新的String [] {strEmail});
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,测试对象);
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,从我的应用程序);
    emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse(文件:///mnt/sdcard/mysdfile.jpg));
    startActivity(Intent.createChooser(emailIntent,发送邮件...));

和确保你在你的清单中添加正确的权限:

 <使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E>

I'm trying to embed a inline image in email body by saving in sdcard and then picking from that place but image is not being shown and just "obj" is shown there.Kindly help me out,here is the code of my function:

   {

    Bitmap newImg=BitmapFactory.decodeByteArray(img,0,img.length);

    String root = Environment.getExternalStorageDirectory().toString();
    File myDir = new File(root + "/saved_images");    
    myDir.mkdirs();
    String fname = "stoneage.jpg";
    File file = new File (myDir, fname);

    try{
           FileOutputStream out = new FileOutputStream(file);
           newImg.compress(Bitmap.CompressFormat.JPEG, 90, out);
           out.flush();
           out.close();

    } catch (Exception e) {
           e.printStackTrace();
    }

    Uri uri = null;
    uri = Uri.parse("file://" + Environment.getExternalStorageDirectory()+"/saved_images/"+fname);


    String txtBody = "<html><body><h1>hi it is stoneage product</h1><br><img src ="+uri+"/></body></html>";
    Log.d("data", txtBody);

    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.setType("text/html");

  emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "testemail");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(txtBody));
    startActivity(Intent.createChooser(emailIntent, "Email:"));  }

解决方案

Try this to save the file:

    try {
        File myFile = new File("/sdcard/mysdfile.jpg");
        myFile.createNewFile();
        FileOutputStream fOut = new FileOutputStream(myFile);
        OutputStreamWriter myOutWriter = 
                                new OutputStreamWriter(fOut);
        myOutWriter.append(txtData.getText());
        myOutWriter.close();
        fOut.close();
        Toast.makeText(getBaseContext(),
                "Done writing SD 'mysdfile.txt'",
                Toast.LENGTH_SHORT).show();
    } catch (Exception e) {
        Toast.makeText(getBaseContext(), e.getMessage(),
                Toast.LENGTH_SHORT).show();
    }





    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
    emailIntent.setType("application/image");
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{strEmail}); 
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Test Subject"); 
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "From My App"); 
    emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/mysdfile.jpg"));
    startActivity(Intent.createChooser(emailIntent, "Send mail..."));

And make sure you add the correct permission in your manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">

这篇关于从节约和Android的SD卡中嵌入采摘电子邮件正文中的一个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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