How to use front and back camera at the same time? - java

I want to use both front and back cameras at the same time. I have used two surface views. I have tried to implement the code in following answer.
https://stackoverflow.com/a/24238301/6874315
The problem is that the camera API is now deprecated and the code was too old. I tried using the Camera 2 API in the same way but the camera instance won't open and i get a blank white screen.
I get the following two errors:
Camera 0 not available! java.lang.RuntimeException: Fail to connect to camera service
Camera 1 not available! java.lang.RuntimeException: Fail to connect to camera service
What i wanna do is capture picture from front and back camera simultaneously on a button click. But i'm not able to open both front and back cameras at the same time.
Is there anything that I do to use both cameras at same time?

Take a look at these answers:
https://stackoverflow.com/a/30444841/11338123
https://stackoverflow.com/a/52075569/11338123
I think it is possible in some devices and it is impossible in others

I don't sure that it is possible to use both cameras simultaneously. But, you could switching between two cameras like in this sample for short time interval.
Also you can modify you program to process camera images in the background thread in such way to avoid GUI freezing.
So, you may try to make a little changes in the sample to get front and back camera instances for testing your idea. Good luck!

Related

Map image blinks while adding more layers to it

I have an application in java swing and geotools. I have displayed a map image and trying to add images as layers to it. When it adds layer it blinks and after some time at the call to addLayer function map image and other few layers disappear for some time. How to stop this? I am loging all the information at the same time in SQLite and then to my own customised file.
I have stopped trying refreshing all after addLayer function call. The all process should work smoothly without blinking and disappearing. Please Help.
The gt-swing module is really only intended for simple demonstrations. If you intend to use it in production you should add in off screen buffering to allow "fast" refreshes of the map without rereading all the displayed data.

Looking for an easy way to capture images on an Android phone as a background service

I'm trying to create an application that automatically clicks pictures as you carry your phone around, the point is that it clicks pictures as you do your own business.
This question is basically what I'm looking for with the added functionality of taking pictures every n seconds. I wanted to know if there was something more efficient than this method (shrinking the preview window to 1x1).
background service is not recommended. You can use foreground service for this job.
You need to give media and camera access permission in the code. Then you can run the capture function with n second delay and while loop as many times as you want.
there are some examples, i don't want to repeat them.
capture, save and show example
take photo without ui

Set rect focus in camera android

I am doing an Android application that uses camera. I want that camera focuses in faces. My dude is: Nexus 5 front camera only has "Fixed" in focus mode. Is there some way to use setRect areas or something like that.
I try to use facedetectionlistener and runs ok but when i also add a previewcallback to do some process stops running. (Issue with preview callback [ANDROID])
Thanks
You might want to take a look at Camera.Parameters. It has setFocusArea and setAutoFocus functions.
Check this one

Registering Coords for two fingers

I want to build an android application that would register the x,y for two fingers on the screen at the same time. Is this possible or does android not allow that?
Your View can keep track of multiple touches in its onTouch method be monitoring the events with the ACTION_POINTER_DOWN flag. Check out this post, and its links, for more help.

is multiple activities and surface views the correct way to go?

I'm currently in the process of making one of my first android games and have come into some difficulty understanding how to make the transitions between screens.. for example:
My game starts its main activity, which then loads TitleScreen surface view which initializes its own thread
on tap I start a new intent which loads a new activity which loads GameView surface view which initializes its own thread
This all works fine when testing on my device (Evo 3d) but crashes on tap on my test bed, I'm using android x86 in virtual box for quick testing. Is this likely to be a problem in my code or a problem with the simulator?
Also I'm wanting to add a level select screen in between the title screen and the game screen and figured i could do this by creating another activity/surface view/thread combo, Is this acceptable coding practice or is this a wasteful/process heavy method?
You could create a variety of methods that you call from your onDraw method. Each method would draw one screen (game, level, score). To start simple a switch case in the onDraw checks the screen and then calls the right thing to draw.
If you want to have different layers, you should use different acitvities so that the background (game) is being paused while the scoreboard is active. This only makes sense if you want the background to be still visible or need the acitivites for other reasons.
But you should never have more than one surface view active at the same time, android doesnt like that.
I think its not good to use more activities for single application. Try to use ViewFlipper with number of xml layout files. Here you can apply transition effects very easily.
I am suggesting you it for transition effects, but you also check it once. I am also thinking which one is good.

Categories

Resources