我的活动有一个imageview,带有用户输入的电子邮件地址的edittext和一个发送按钮。在发送按钮活动中,我已准备好电子邮件,主题和收件人姓名,但我还想添加imageview包含的图像。
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setData(Uri.parse("mailto:"));
intent.setType("image/jpeg");
intent.putExtra(Intent.EXTRA_EMAIL, receivers);
intent.putExtra(Intent.EXTRA_SUBJECT, "My subject");
intent.putExtra(Intent.EXTRA_TEXT, "hello wats up");
intent.putExtra(Intent.EXTRA_STREAM, image i want to send);
startActivity(intent);
显然最后一个putExtra行会给我一个错误,说明他们想要字符串,但我正在通过imageview。请指导我如何在此电子邮件正文中包含我的imageview。 (不是作为附件,而是在带有消息文本的消息正文中)。
非常感谢你们。
答案 0 :(得分:1)
您已将fileUri作为第二个参数传递。像这样。
intent.putExtra(Intent.EXTRA_STREAM, fileUri);
答案 1 :(得分:1)
试试如下:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/*");
Uri uri = Uri.parse("android.resource://your package name/"+R.drawable.ic_launcher);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.putExtra(android.content.Intent.EXTRA_EMAIL,recipients);
shareIntent.putExtra(Intent.EXTRA_TEXT, message);
startActivity(Intent.createChooser(shareIntent, "Send your image"));
编辑:
声明File变量,如下所示
File pic;
在您的OnActivityResult()中应用如下更改:
Bundle ext = data.getExtras();
bmpEmail = (Bitmap)ext.get("data");
try {
File root = Environment.getExternalStorageDirectory();
if (root.canWrite()){
pic = new File(root, "pic.png");
FileOutputStream out = new FileOutputStream(pic);
bmpEmail.compress(CompressFormat.PNG, 100, out);
out.flush();
out.close();
}
} catch (IOException e) {
Log.e("BROKEN", "Could not write file " + e.getMessage());
}
在您的发送电子邮件地址中添加
行 emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(pic));
答案 2 :(得分:0)
试试这个
ImageView iv = (ImageView) findViewById(R.id.splashImageView);
Drawable d =iv.getBackground();
BitmapDrawable bitDw = ((BitmapDrawable) d);
Bitmap bitmap = bitDw.getBitmap();
File mFile = savebitmap(bitmap);
然后
Uri u = null;
u = Uri.fromFile(mFile);
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("image/*");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Hello...");
// + "\n\r" + "\n\r" +
// feed.get(Selectedposition).DETAIL_OBJECT.IMG_URL
emailIntent.putExtra(Intent.EXTRA_TEXT, "Your tsxt here");
emailIntent.putExtra(Intent.EXTRA_STREAM, u);
startActivity(Intent.createChooser(emailIntent, "Send email..."));
和savebitmap方法
private File savebitmap(Bitmap bmp) {
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
OutputStream outStream = null;
File file = new File(extStorageDirectory, temp + ".png");
if (file.exists()) {
file.delete();
file = new File(extStorageDirectory, temp + ".png");
}
try {
outStream = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
} catch (Exception e) {
e.printStackTrace();
return null;
}
return file;
}
答案 3 :(得分:0)
:nth-of-type(n)
只要您使用EXTRA_STREAM,就会添加附件。
如果您希望将图像放在电子邮件正文中,则应发送html邮件。不是纯文本邮件。