23

I am trying to take multiple photos using the default device camera application launched through an intent (MediaStore.ACTION_IMAGE_CAPTURE). With the devices I am testing with, the camera launches, takes a picture, asks for confirmation, then returns to my activity where I process the result.

I've considered using broadcast receiver callbacks or a content observer; however, I cannot find a way to launch the camera and keep it active until the user is finished. If possible, I wish to avoid developing a custom camera application.

The reason I must do this is because users commonly need to take multiple photos in succession, and on some devices the camera start-up time is upwards of 5 seconds, and the users using the software take 10 - 30 photos consecutively; not only that, but they need control over various camera parameters.

Is there a way to launch the camera intent and only return to my activity once the user exits the camera application?

Chris Hutchinson
  • 9,082
  • 3
  • 27
  • 33

1 Answers1

22

I discovered through the SDK documentation that there's an alternative intent action for the device camera that launches the camera in still image mode and does not exit until the user is finished with the activity:

Intent intent = new Intent(
    MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
this.startActivity(intent);

Coupled with a ContentObserver this was exactly what I needed to accomplish.

Chris Hutchinson
  • 9,082
  • 3
  • 27
  • 33
  • it s working fine.but when i am pressing back key.i am getting null pointer exception.can you suggest me how can i get rid of it. – Meghna Mar 29 '14 at 14:37
  • @Chris Hutchinson : its taking multiple images. but how to get the captured image path or fileName into our application? – John Aug 26 '15 at 09:34
  • This was quite some time ago, but the best method I encountered was using a ContentObserver to detect when an image is created. If you don't find that reliable enough, you can check if the path is within the phone's camera directory. There may be an API to locate this directory. I can't remember. – Chris Hutchinson Aug 27 '15 at 17:30
  • http://stackoverflow.com/questions/6448856/android-camera-intent-how-to-get-full-sized-photo?rq=1 – Chris Hutchinson Aug 27 '15 at 17:31
  • 2
    Hi, how did you used ContentObserver here? Please help, having same situation. – Calin Martinconi Jun 14 '16 at 21:42
  • 1
    ContentObserver has a major flaw. You have to stop observing the photos directory when the camera intent is finished. But what if someone closes the application before coming back from camera intent? You observer will be still working and picking up new photos if someone uses the camera application outside your app. – kazuar Sep 29 '16 at 14:03
  • I have found a possible solution to this problem. Setting a value to the shared preference when the intent is called and resetting the value when someone exits the app- will it solve the problem? @kazuar – Preetom Saha Arko Jan 12 '18 at 12:12
  • As you said, This Action does not exit after capturing image and allowing to capture another image. But how can i get those captured images to activityResults, like ACTION_IMAGE_CAPTURE. – Raj Jun 25 '20 at 00:25