Java 在内联电子邮件正文中发送base64编码图像
我正试图通过嵌入数据的html以电子邮件正文的内联形式发送图像。html显示正确,但图像现在显示在图像的位置。我看到一个写为“obj”的小块。我还将位图img转换为base64格式。代码如下:Java 在内联电子邮件正文中发送base64编码图像,java,android,base64,html-email,Java,Android,Base64,Html Email,我正试图通过嵌入数据的html以电子邮件正文的内联形式发送图像。html显示正确,但图像现在显示在图像的位置。我看到一个写为“obj”的小块。我还将位图img转换为base64格式。代码如下: public void imageRetrieved(byte[] img) { Bitmap newImg=BitmapFactory.decodeByteArray(img,0,img.length); ByteArrayOutputStream baos = new By
public void imageRetrieved(byte[] img)
{
Bitmap newImg=BitmapFactory.decodeByteArray(img,0,img.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
newImg.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
String imageEncoded = Base64.encodeToString(b,Base64.DEFAULT);
Log.d("LOOK", imageEncoded);
String txtBody = "<html><body><h1>hi it is stoneage product</h1><br><img src ='data:image/jpeg;base64,"+imageEncoded+"'/></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:"));
检索到的公共无效图像(字节[]img)
{
位图newImg=BitmapFactory.decodeByteArray(img,0,img.length);
ByteArrayOutputStream bas=新的ByteArrayOutputStream();
newImg.compress(Bitmap.CompressFormat.JPEG,100,baos);
字节[]b=baos.toByteArray();
字符串imageEncoded=Base64.encodeToString(b,Base64.DEFAULT);
Log.d(“外观”,图像编码);
String txtBody=“嗨,这是石器时代的产品”; Log.d(“数据”,txtBody); Intent emailIntent=新的Intent(android.content.Intent.ACTION\u SEND); emailIntent.setType(“text/html”); emailIntent.putExtra(android.content.Intent.EXTRA_主题,“testemail”); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,Html.fromHtml(txtBody)); startActivity(Intent.createChooser(emailIntent,“Email:”); }
请帮帮我试试这个它对我有用
File pngDir = new File(Environment.getExternalStorageDirectory(),"saved_images/");
if (!pngDir.exists())
{
pngDir.mkdirs();
}
File pngfile=new File(pngDir,"stoneage.jpg");
Uri pngUri =Uri.fromFile(pngfile);
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{""});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "hi it is stoneage product Hi this is test mail with attachment");
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM,pngUri);
emailIntent.setType("message/rfc822");
startActivity(Intent.createChooser(emailIntent, "Email:"));
如果不工作比简单保存位图图像到SD卡,并给予它,路径我也这样做了,但我不知道为什么仍然有“obj”正在显示在图像的地方现在我的代码就像嗨它是stoneage产品
我感谢你的回应@Amit,但新更新的代码也不工作相同的“obj”显示在图像的位置。请尝试将SD卡上已保存的图像附加到base64,而不是已转换的base64