1
I’m making a native Android application using the device’s cameras. After I start the first Activity, calling the camera (Back), I created a button, with the function of switching between the cameras (Front, Back).
It’s just that I’m having a little trouble doing that job. Take the camera that is being used and switch to another one, type (Front --> Back/ Back --> Front). Could help me solve this problem?
Code below -->
public void cameraFrontal(View view){
int numCamera = Camera.getNumberOfCameras();
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
if(numCamera < 0){
Log.i("Script", "Nenhuma câmera encontrada");
}else {
if(cameraManager.isOpen() == true && numCamera == 2){
Log.i("Script", "Camera --> " + cameraInfo.facing);
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
Toast.makeText(this, "Chamada da Câmera Frontal", Toast.LENGTH_LONG).show();
}else if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
Toast.makeText(this, "Chamada da Câmera Traseira", Toast.LENGTH_LONG).show();
}
}
}
}
What have you ever tried to do?
– Jorge B.
I’m just checking to see if there are cameras on the device, Camera.Camerainfo cameraInfo = new Camera.Camerainfo(); if(numCamera < 0){
– Patrick Rodrigues
After that, it was to check which camera is running (Front or Rear). Done this, put function to switch between them, using a Button, for example.
– Patrick Rodrigues
You can [Dit] the question by placing the relevant code.
– Maniero
In fact, I wanted to do what every time I clicked on the button, the method identified which camera is running (whether it’s the front or the back) and then switched the camera, if I was using the rear camera would switch to the front and so vice versa.
– Patrick Rodrigues