如何在android java中将位图图像附加到电子邮件中?

时间:2015-12-27 20:47:15

标签: java android email bitmap

我使用下一个代码,但我有一个例外:

FileOutputStream out = new FileOutputStream(pic);

这是我使用的功能:" frame"是来自相机的令牌的Bitmap,我在ImageView上显示它。 " PIC"是一个文件。

public void sendEmail(View view) {

    String email = "michael@gmail.com";
    String subject = "frame";
    String message = "This is the frame!";
    try {
        File root = Environment.getExternalStorageDirectory();
        if (root.canWrite()){
            pic = new File(root, "image.jpeg");
            FileOutputStream out = new FileOutputStream(pic);
            frame.compress(Bitmap.CompressFormat.JPEG, 100, out);
            out.flush();
            out.close();
        }
    } catch (IOException e) {
    }

    final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.setType("image/jpeg");
    emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{email});
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, message);
    emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(pic));
    startActivity(Intent.createChooser(emailIntent, "Sending email..."));
}

0 个答案:

没有答案