android - 将可绘制文件夹中的图像附加到gmail中

标签 android email

我的可绘制文件夹中有一些图像,还有这些图像的 int 数组。现在我正在尝试通过 gmail 发送带有我的可绘制文件夹中的附加图像的电子邮件,在 android 2.3 中一切正常,但在 android 4.0 中图像的扩展名丢失。我没有找到任何解决方案。下面是我使用的代码。

Uri imageuri  = Uri.parse("android.resource://MyPackageName/" + SplashActivity.mBitmap_mixed_images[int_image_position]);

            Intent intent = new Intent(Intent.ACTION_SEND); 

               if(imageuri != null){
                intent.putExtra(Intent.EXTRA_STREAM, imageuri);
                intent.putExtra(Intent.EXTRA_SUBJECT, "150+ Reasons to Quit Smoking");
                //intent.putExtra(Intent.EXTRA_TEXT, "www.selftalk.info");
                intent.setType("image/html");
               }else{
                intent.setType("plain/text");
               }
               final PackageManager pm = getPackageManager();
                final List<ResolveInfo> matches = pm.queryIntentActivities(intent, 0);
                ResolveInfo best = null;
                for (final ResolveInfo info : matches)
                  if (info.activityInfo.packageName.endsWith(".gm") ||
                      info.activityInfo.name.toLowerCase().contains("gmail")) best = info;
                if (best != null)
                  intent.setClassName(best.activityInfo.packageName, best.activityInfo.name);
                startActivity(intent);

最佳答案

private FileOutputStream outStream; 
private File file;
Bitmap bm = BitmapFactory.decodeResource( getResources(), R.drawable.ic_launcher);
        String extStorageDirectory = Environment.getExternalStorageDirectory().toString();

    file = new File(extStorageDirectory, "ic_launcher.PNG");
    try {
        outStream = new FileOutputStream(file);
        bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
        outStream.flush();
        outStream.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

email = new Intent(Intent.ACTION_SEND);
email.setType("application/octet-stream");
email.putExtra(Intent.EXTRA_EMAIL, new String[] { "" });
email.putExtra(Intent.EXTRA_SUBJECT, "My Subject");
email.putExtra(Intent.EXTRA_TEXT, "");
email.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
startActivity(Intent.createChooser(email, "Choose an Email client :"));

关于android - 将可绘制文件夹中的图像附加到gmail中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18143199/

相关文章:

android - 无法解析 com.android.tools.build :gradle:3. 2.1

android - 在 float Activity 中运行YouTube视频

python - 使用 python 从 axigen 服务器读取电子邮件

bash - Debian:使用 TCP 的 Bash 电子邮件

android - 当我们创建连接时,后台会向 MQTT 服务器发送哪些信息(Ex : device ID, MAC 等...)?

android - 应用程序错误 - 与服务器的连接不成功。

python - Django - 发送电子邮件在 shell 中有效,但在本地主机上无效 - ConnectionRefusedError

email - 在 SAS SQL 中计算电子邮件地址中的连续辅音

node.js - Nodemailer 不适用于 Amazon EC2 实例

android - 无法检查我的textview在Kotlin中是否可见数组内部