1

I use next code, but I have an exception in this:

FileOutputStream out = new FileOutputStream(pic);

Here is the function I use: "frame" is a Bitmap that token from camera and I show it on ImageView. "pic" is a File.

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..."));
}
Christian
  • 25,249
  • 40
  • 134
  • 225
  • "I have an exception in this: FileOutputStream out = new FileOutputStream(pic);" -- use LogCat to examine the Java stack trace associated with your crash: https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this For this to work, you will need to actually log the exception from your `catch` block. – CommonsWare Dec 27 '15 at 20:49
  • You can examine http://stackoverflow.com/questions/587917/trying-to-attach-a-file-from-sd-card-to-email – msevgi Dec 27 '15 at 21:18

0 Answers0