在android的SD卡中保存和拾取的邮件正文中嵌入图像
我正试图通过保存在SD卡中,然后从该位置选择,将内联图像嵌入电子邮件正文,但图像未显示,仅显示“obj”。请帮助我,以下是我的函数代码:在android的SD卡中保存和拾取的邮件正文中嵌入图像,android,image-processing,html-email,android-sdcard,email-client,Android,Image Processing,Html Email,Android Sdcard,Email Client,我正试图通过保存在SD卡中,然后从该位置选择,将内联图像嵌入电子邮件正文,但图像未显示,仅显示“obj”。请帮助我,以下是我的函数代码: { Bitmap newImg=BitmapFactory.decodeByteArray(img,0,img.length); String root = Environment.getExternalStorageDirectory().toString(); File myDir = new File(root + "/
{
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:")); }
{
位图newImg=BitmapFactory.decodeByteArray(img,0,img.length);
String root=Environment.getExternalStorageDirectory().toString();
File myDir=新文件(root+“/saved_images”);
myDir.mkdirs();
字符串fname=“stoneage.jpg”;
File File=新文件(myDir,fname);
试一试{
FileOutputStream out=新的FileOutputStream(文件);
newImg.compress(Bitmap.CompressFormat.JPEG,90,out);
out.flush();
out.close();
}捕获(例外e){
e、 printStackTrace();
}
Uri=null;
uri=uri.parse(“文件:/”+Environment.getExternalStorageDirectory()+“/saved_images/”+fname);
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:”);}
尝试以下方法保存文件:
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..."));
并确保在清单中添加正确的权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">
我已添加权限,图像正在SD卡中保存。。。问题是,即使我从我的绘图资源中添加了图像,它也没有嵌入到电子邮件正文中,同样的问题也在发生,我已经编辑了上面的代码。从你的代码来看,你似乎从未将图片作为附件添加。图片附件100%正常工作,但我想在电子邮件的内联正文中发送图片。无论如何,感谢你的贡献。现在我决定附加图片。