android - 在android中通过邮件分享图像

标签 android

在我的 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/

相关文章:

java - 如何在android Canvas 中绘制一个实心三角形?

android - sqlite查询运行时错误

Java获取一周中最近传入的某一天的日期

android - 当我将代码从 Java 转换为 Kotlin 时出现错误 "Expecting member declaration",为什么?

java - 为一个 Activity 中的多个列表定义 onItemClick 行为的正确方法?

android - 索尼智能 watch 2 中的 ListView

Android前置摄像头图像保存颠倒

java - 如何防止键盘和菜单同时显示?

java - 如何修复我的 Android Soundboard 应用程序的 "Google Mobile Ads SDK was initialized incorrectly"

android - ImageView onImageChangedListener 安卓