0

I am trying to make an app that will let me take some photos and then send them to someone by e-mail. Taking photos and emailing does work but how do I attach the photos to the email?

This is the code I use to take the photo in intent One:

public void maak_foto(View view) {

    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

    File pictureFileDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    File FileDir = new File(pictureFileDir, "offerte_fotos");

    try {
        FileDir.mkdirs();
    }finally {

    }

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyymmddhhmmss", Locale.getDefault());
    String date = dateFormat.format(new Date());
    String photoFile = "OfferteFoto_" + date + ".jpg";

    String filename = pictureFileDir.getPath() + File.separator + photoFile;

    File photo = new File(filename);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
    imageUri = Uri.fromFile(photo);
    startActivityForResult(intent, TAKE_PICTURE);
}


@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case TAKE_PICTURE:
        if (resultCode == Activity.RESULT_OK) {
            Uri selectedImage = imageUri;
            getContentResolver().notifyChange(selectedImage, null);
            ContentResolver cr = getContentResolver();



            try {
                bitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, selectedImage);


                bitmap.recycle();
                Toast.makeText(this, selectedImage.toString(), Toast.LENGTH_LONG).show(); 
                Log.i("IMAGE_PATH", selectedImage.toString());
            } catch (Exception e) {
                Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT).show();
                Log.e("Camera", e.toString());
            }
        }
    }
}

and this is the code I use to send the email in another intent. (when clicked on next)

        String to = "email adres goes here";
    String verkoopmail[] = { to } ;
    String message = "Hallo verkoop, "
            + '\n' + "Dhr./Mevr. " + contactpersoon + " van " + bedrijfsnaam + " wil graag een offerte ontvangen voor een " + soortbouw + "." 
            + '\n' + "De algemeene contact gegevens zijn:"
            + '\n' + "Adres: " + adres
            + '\n' + "Telefoon nummer: " + telefoon
            + '\n' + "Email adres: " + email;


    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
    emailIntent.setType("image/jpeg"); //text/plain
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, verkoopmail);
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Offerte aanvraag");
    emailIntent.putParcelableArrayListExtra(android.content.Intent.EXTRA_STREAM, uris);

    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
    startActivity(emailIntent);

I cannot find out how to get the URIs from the take photo intent to the send email intent. I am probably doing something wrong somewhere.

Hope someone can help.

Jeroen
  • 1
  • 2
  • See this question for adding file to e-mail via intent http://stackoverflow.com/q/6078099/8524 – Diederik Mar 15 '13 at 19:26
  • I know how to get the uri from the saved photo but how do I add them to/use them in the next intent? – Jeroen Mar 16 '13 at 18:14
  • Do you mean the photos URI after you have taken the pictures? If your intent asked the camera app to take one picture, then the filename you provided it with calling `intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));` should save the pic using that filename. Then you can just attach that file to the email Intent. Only catch is that AFAIK there is no way of asking camera app for more than one pic. You will have to query the Camera's output folder and do date matching unfortunately. – Diederik Mar 17 '13 at 08:21
  • What I want is... open photo intent, take multiple pictures, save the URi's, open second intent (email intent), attach the taken photo's (use the saved uri's), send the email. I can get one photo to be attached but when I make more photo's they aren't attached. – Jeroen Mar 17 '13 at 12:02
  • It's working now... don't know what I did right but it works. – Jeroen Mar 18 '13 at 10:35

0 Answers0