1

When I begin the camera intent I give it a file name I would like it to use. When I get this on the phone it uses the phones default file name. Which is no help as I need the image name later in the app.

Camera intent code...

public void onClick(View view) {
  String currentDateTimeString = DateFormat.getDateInstance().format(new Date());
  System.out.println(currentDateTimeString); 
  filename = ("/sdcard/" + currentDateTimeString + ".jpg");

  Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  File file = new File(Environment.getExternalStorageDirectory(), filename);

  outputFileUri = Uri.fromFile(file);
  intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
  startActivityForResult(intent, TAKE_PICTURE);
  filetype = "image/jpeg";

}
Jakub Hampl
  • 39,863
  • 10
  • 77
  • 106
James
  • 486
  • 1
  • 9
  • 24

1 Answers1

3

James,

Here is the function I use to capture an image and save it to a location of my choosing (sub folder with my app name).

public void imageFromCamera() {
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
        Log.d(TAG, "No SDCARD");
    } else {
        mImageFile = new File(Environment.getExternalStorageDirectory()+File.separator+"MyApp",  
            "PIC"+System.currentTimeMillis()+".jpg");
        mTempImagePath = mImageFile.getAbsolutePath();
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mImageFile));
        startActivityForResult(intent, TAKE_PICTURE);
    }
}
Will Tate
  • 33,439
  • 9
  • 77
  • 71
  • it gives java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { act=inline-data (has extras) }} to activity { – nicky Oct 03 '12 at 18:45