2

Hello i have build an android app which uses the camera to take a picture and then send it as a email attachment.

Its works fine on a htc phone but it does not work on a samsung galaxy which only sends a empty attachment to my mail.

Does someone have a suggestion how to fix this?

my code:

    private final static int TAKE_PHOTO_CODE = 1;
File downloadedPic = null;
Intent in;
boolean taken = false;

//NEW
private static int TAKE_PICTURE = 1;
private Uri outputFileUri;


    private void TakePhoto() {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File file = new File(  
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "fotowedstrijd.jpeg");
    outputFileUri = Uri.fromFile(file);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
    startActivityForResult(intent, TAKE_PICTURE);
}

private void sendPhoto(){
Intent picMessageIntent = new Intent(Intent.ACTION_SEND);
picMessageIntent.putExtra(Intent.EXTRA_EMAIL  , new String[]{"info@wemait.nl"}); //fotowedstrijd@openbedrijvendagemmen.nl
picMessageIntent.putExtra(Intent.EXTRA_SUBJECT, "Fotowedstrijd inzending Openbedrijvendag Emmen");
picMessageIntent.putExtra(Intent.EXTRA_TEXT   , "Mijn inzending voor de fotowedstrijd");
picMessageIntent.setType("image/jpeg");  
File downloadedPic =  new File(  
    Environment.getExternalStoragePublicDirectory(  
    Environment.DIRECTORY_PICTURES),  
    "fotowedstrijd.jpeg");  
picMessageIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(downloadedPic));  
startActivity(picMessageIntent); 
//startActivity(Intent.createChooser(picMessageIntent, "Send your picture using:"));
}
ddnl
  • 495
  • 1
  • 6
  • 22
  • I'm experiencing the same problem. The gmail client sends the attachment but the samsung email client doesn't. Did you manage to fix this? – Jorge Garcia Mar 05 '13 at 09:17
  • Do you delete the file afterwards? Perhaps on the onActivityResult. I was saving a cached version of the file and deleting it after the share and that was causing the problem. Apparently the email client doesn't grab the image in that moment but later (once the file was already deleted) – Jorge Garcia Mar 05 '13 at 09:38
  • I had the same problem with samsungs email client didn't manage to fix this :( i didn't delete the files left it in the cache – ddnl Mar 08 '13 at 14:16
  • Did you use the cache in local storage "getCacheDir"? That directory is private and not accesible for other apps. – Jorge Garcia Mar 09 '13 at 11:23

2 Answers2

1

What I found: Android ACTION_IMAGE_CAPTURE Intent

what it says is that there might be a bug with MediaStore.ACTION_IMAGE_CAPTURE.

Something else, that came to my mind: Maybe the directory doesn't exist on your samsung phone, so you have to create it first.

just some first guesses.

Community
  • 1
  • 1
1

please take a look on my extract code, i used to have the same problems on my samsung Galaxy S2, like:

  1. i use samsung galaxy S2 and i could not put the attachement photo on the email client , so i copied the code from another guy that made a tutorial just for samsung, and it works.

  2. when i choose to send the email via the default email client ,that samsung has, the app it crashes but when i send it from the gmail email client it works.

my code is here : Android take photo and send it as an attachment to an email, imageview reset on rotation

inside the onActivityResult method i check the requestcode of the camera and i load the photo that i have taken , on an imageview, after that it is easy to put it as an attachment (i do this on the method email() ).

Community
  • 1
  • 1
Theo Itzaris
  • 4,321
  • 3
  • 37
  • 68