Android: How to capture multiple photos with the s

2019-08-03 04:26发布

问题:

I made an Android app that takes photos one by one, stores them, gives a preview to the user, etc...all of these tasks are accomplished with an intent of type ACTION_IMAGE_CAPTURE.
So, each time that the user wants to make a photo, he should click on the "take photo button" that starts an intent, and after having waited some seconds to start the camera, the user is able to take a picture; after that the photo is taken and accepted by the user, the camera closes and the picture taken is given back (as a bitmap for the preview) to the calling class via an onActivityResult method.
Now, if you want to do more than one photo, this procedure can be really tedious.

So, I would like to provide my app with a modality that allows the user to take more than one photo without all the slow stuff mentioned above.
Just to clarify, I don't want to make a burst mode (photos taken automatically after predefined intervals of time) but I want to make the user able to click the shutter to take photos as much time as he wants without being interrupted by other things.

Searching on the net, I found some information and it seems to me that there are three possible ways to pursue:
- making an intent to "INTENT_ACTION_STILL_IMAGE_CAMERA": this one is easy to implement, but the camera interface will depend heavily on the app that is called when the intent is made (for example on my One Plus Three, the app called to accomplish this task is "Camera FV-5 Lite", on the emulated device is another one)...as a consequence, I think that is not possible to control the interface or the behavior of the called app (for example, on the app called via intent is possible to switch to video mode, but this shouldn't be possible to do in the app that I'm designing);
- using the package "Camera2" (https://developer.android.com/reference/android/hardware/camera2/package-summary.html): Google provides some examples of this package here https://github.com/search?utf8=%E2%9C%93&q=android-Camera2&type= but I don't fully understand how can be difficult to take this route;
- make a picture taking code by yourself: I think that this is the most difficult way.

It is possible for a beginner-intermediate developer to accomplish this task following one of the way mentioned above (or a different one)?

Similar questions:
- Taking Multiple Photos from Android device : here is asked how to speed up the process and reduce the lag between one photo and another one;
- Making a gallery with automatically generated ImageView s: this question is about updating the gallery dynamically with photos made via different intents to ACTION_IMAGE_CAPTURE;
- How to take multiple photos before dismissing camera intent?: this one talks about the solution with the intent to INTENT_ACTION_STILL_IMAGE_CAMERA coupled with a ContentObserver, that I don't want to pursue as mentioned above;
- Issues when capturing Multiple Photos: app stops responding, camera preview turns to green and no picture is saved: old post that talks about issues when capturing more than one photo, but one answer is interesting because Camera2 is mentioned.

回答1:

making an intent to "INTENT_ACTION_STILL_IMAGE_CAMERA"

This is not really analogous to any of your other options. For example, you have no idea if any pictures were taken, where they were stored, etc.

as a consequence, I think that is not possible to control the interface or the behavior of the called app

Correct. This is the same as with ACTION_IMAGE_CAPTURE.

using the package "Camera2"

This is the same as "make a picture taking code by yourself", except that you identified a particular Android API for it.

It is possible for a beginner-intermediate developer to accomplish this task following one of the way mentionned above (or a different one)?

Use a third-party camera library (Fotoapparat, CameraKit-Android, etc.).