在我的 Android 应用程序中,我通过蓝牙共享图像是有效的。同时我尝试通过邮件分享。但该邮件未附有图像。它仅与正文一起发送。 有什么解决办法吗?
最佳答案
要通过电子邮件作为附件发送图像,您首先需要将其另存为 SD 卡上的文件。如果您的图像是位图,那么您可以将其写入如下文件
OutputStream fOut = null;
String fileName = Environment.getExternalStorageDirectory()+"/myImage.png";
File file = new File(fileName);
fOut = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 85, fOut);
fOut.flush();
fOut.close();
然后使用Intent
,启动电子邮件客户端应用程序,并将图像文件作为附件
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("image/jpeg");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {""});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, EMAIL_SUBJECT);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, EMAIL_BODY);
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+fileName));
startActivity(Intent.createChooser(emailIntent, "Sharing Options"));
关于android - 在android中通过邮件分享图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11605576/