How to capture images in background using Camera2 api? - android

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?

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.

Related

How to configure front and back both cameras simultaneously in Android camera2 API?

I want to configure front and back both cameras into Android camera2 API, to take pictures and videos from both cameras simultaneously, I have created 2 texture views , when ever I am opening one camera (front or back) my code is working fine but whenever I am trying to open both cameras simultaneously , code is breaking upon creating session, I am getting cameraAccessException :configure stream : method not implimented.
I want to save both front and back camera captured images as one image and both video as one video.
Guys it will be very much helpful if you can put some sample code or some sample link.
i am using one plus 6, i recently downloaded an app "Dual camera fron back Camera", by using this i am able to capture image from front and back both camera on the same time, so if somebody want to suggest for no hardware support, i think it may be valid for other phones but for my case i think i am missing something in coding, till now from google search it looks like there is some problem with session creation for second camera, i debugged my code, during creation of second camera session it fails so if you have any idea about that, please share.
Thanks
Rakesh
The camera API is fine with it, but most Android devices do not have sufficient hardware resources to run both cameras at once, so you will generally get an error trying to open the second camera.
Both image sensors are typically connected to the same image signal processor (ISP), and that ISP can only operate one camera at a time. Some high-end devices have ISPs with multiple processing pipelines which can in theory run more than one camera at a time, but they often require using multiple pipelines to handle advanced functionality or very high resolutions for the main (back) camera.
So on those devices, multiple cameras may be usable at once, but not at maximum resolution or other similar restrictions.
Some manufacturers include multi-camera features in their own camera app, since they know exactly what the limitations are and can write application code to work within them. They may not make multi-camera available to normal apps, due to concerns about performance, thermal limits, or just lack of time to verify more than the exact use case they implement in their own app.
The Android camera API does not currently have a way to query if multiple cameras can be used at once, or if they can be, what the restrictions are. So the only thing you can do is try, and handle the errors in case that isn't feasible.

Android SDK 4.0 Reading Camera Preview Frames only in a Service without Activity

I'm working on a computer-vision application that uses rear camera.
I'm using Android SDK for 4.0 (API 14)
I spent a few days trying to get preview frame in realtime, through onPreviewFrame, but have failed so far.
I think that the camera actually invoke preview callback when the previewDisplay is actually rendered in an activity.
But I have to capture camera images only in a service, without activity.
Any suggestions for this?
I've already tried making dummy surfaceView but it won't work.
I suggest trying Service.startActivity(intent)
Services don't have a UI, you need an Activity for that. But you can start an Activity from your Service.
Also, I don't think you can take a picture without the user's knowledge.

Is it possible to process the video (preview) stream without displaying it on the screen in android?

I have doing a basic object detection on the camera preview screen in Android (greater than 3.2). For the devices which do not support processing on preview screen, I am buffering the preview screen, processing it and clearing the buffer. This part is working as desired.
What I now want is this app to run in the background while any other app is running in the foreground. I am using android service and am able to run a small test app in the background. However my concern is with the camera preview app.
I don't want to display the preview screen but use the preview screen information for processing. This might be too much to ask, but I wanted to know if this is even possible. I came across this link which shows some hope. Basically I want to process the video (preview) stream without displaying it on the screen. If this is doable, then I can think of putting this app in the background and some other app in the foreground.
Unfortunately I won't be able to share the code, however it is the standard logic of creating a surface view and starting the preview.
I would really appreciate any insight into this.
Check comments here.Basically he opens camera hardware, set preview callback and do startpreview without setting the previewDisplay (this might not work on every device). You can try this from your background service. All this will work if your foreground doesn't access the camera app. Please update this if it works. I am interested to know.

android camera in background

I am developing an application to take images from background application say using android service. i don't want any user interaction to takes images, it should completely work from background.
I have already tried -
Calling camera from service - It not always works sometime works if we have dummy surfaceview, again if Android close the related activity service stopped takings pics, I don't want to run activity for user interaction.
with some changes it working fine but all images are black.
Widget: Not getting how to call camera in widget as widget doesn't support surfaceview.
Live wallpaper: not able to make it work till now, does it supports for camera?
As per my experience till now Android camera service not designed to takes picture if no real preview available.
Is anyone developed something like this? any help will be really appreciate.
If you can ignore older versions, it may be easier to use SurfaceTexture (API 11 and higher) As vikky.rk notes in an answer to a recent question, an introduction to this technique can be found in the PanoramaActivity code of the default Android Camera App.

Can I control the flashlight without using android.hardware.Camera?

The use of front light option with zxing1.6 barcode scanner does not work on my Nexus One. I need to be able to use the flashlight in my app, but you can't have two instances of the camera running. Is there a way to use the flashlight without accessing the camera? Or can I somehow access a camera that is already in use?
I am using the Google IntentIntegrator.java patch to be able to scan barcodes.
The short answer is "no"; the front LED is controlled as a flash mode, which is a property of the camera. It is mode "torch". And no two apps can't open the camera at the same time.
(A longer answer is that there used to be a hidden API for this, which is what Barcode Scanner tries to access, but it doesn't work on almost any device anymore. You can dig into the source code to see FlashlightManager.)
Since Android 2.x there is this proper API for turning on the light, and the beta of the next version of Barcode Scanner does use it. You can try it here.

Categories

Resources