I am developing an Android security app, and I want to capture images in background without preview. Is it possible to capture images in the background using the camera2 api?
Asked
Active
Viewed 1,396 times
1 Answers
0
Yes, but as of Android 5.0 Marshmallow, you may be disconnected from the camera at any time, if a foreground app wants to use it instead.
And before Android M, using the camera from the background is not recommended, since you'll block any foreground app from using it (the app will just get an error trying to open the camera, and generally will crash as a result).
Otherwise, the camera API works the same. You'll need to run the camera for a few seconds before taking the final picture to ensure metering and focus are generally good, though exactly what you need would depend highly on the details of your use case.

Eddy Talvala
- 17,243
- 2
- 42
- 47
-
Would you mind to give me sample code to capture images without preview for Android M ? – Getaw Dejen Apr 21 '16 at 22:00
-
If on the deprecated Camera API, use a dummy SurfaceTexture (see http://stackoverflow.com/questions/10775942/android-sdk-get-raw-preview-camera-image-without-displaying-it/10776349#10776349). If on camera2, create a capture session with two outputs - one low-resolution that you can run for a few dozen frames to converge metering and focus, and one high-resolution for your still capture. – Eddy Talvala Apr 26 '16 at 19:55