1

i've been trying to create a camera-related app. i know that i could create it programmatically from top, but i would prefer using the one that the phone supports.

what i mean is, rather then creating the camera from 0, i would/could call the camera activity. after all, it provides all the system and gui that i needed.

however, the problem is i wanted the result/image took to be saved in a folder that i created before, rather then saving it in the default camera folder. and also renaming the image took that instant from the default 'image' to names that i preferred.

how do i control that ?

starvi
  • 519
  • 4
  • 15
  • 29

3 Answers3

2

Try this. Here am saving picture to sdcard and also changing its name while saving.

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

Uri mUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),
                "pic"+ String.valueOf(System.currentTimeMillis()) + ".jpg"));

intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mUri);
Chintan Khetiya
  • 15,962
  • 9
  • 47
  • 85
anju_john
  • 76
  • 4
1

If you look at the Camera applicaton source code, it allows for startActivityForResult(..) that can return the image back to you. This is ideally what you'd like to do.

As a Little hint:

MediaStore

JoxTraex
  • 13,423
  • 6
  • 32
  • 45
0

Use below method to take picture, SD_CARD_TEMP_DIR is the path and the image name you want it to store. Hope it help

     private void   takePicture(){

    SD_CARD_TEMP_DIR = Environment.getExternalStorageDirectory() + File.separator + "farmerImage"+CassavaPref.getInstance(this).getImageSuffix()+".jpg";
    file =new File(SD_CARD_TEMP_DIR);
    Intent takePictureFromCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    takePictureFromCameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
    startActivityForResult(takePictureFromCameraIntent, 1111);
}
AAnkit
  • 27,299
  • 12
  • 60
  • 71
  • 01-22 17:56:04.470: E/AndroidRuntime(4924): FATAL EXCEPTION: main 01-22 17:56:04.470: E/AndroidRuntime(4924): java.lang.NullPointerException – starvi Jan 22 '12 at 09:56
  • first. add permision " write external storage" in your manifest, and give in which line you are getting expception – AAnkit Jan 22 '12 at 10:00