The samsung galaxy a6 phone has a front camera with its own flash. That is, there are flashlights on both sides. Is it possible to somehow call the front flash in the application so that it turns on by the button?
Is it possible to make the flashlights turn on on both sides of the phone when the button is pressed, that is, both the rear and the front?
Answer 1, authority 100%
It is done like this:
- Get a link to
cameraManager = (CameraManager) getSystemService (CAMERA_SERVICE);
- Get a list of all cameras
- Next, go through all the cameras and request
cameraManager.getCameraCharacteristics (String cameraId)
- In the resulting object of the
CameraCharacteristicsclass, we request the
LENS_FACINGproperty, if the property is
FRONT, then this is a front camera
- Next, request the
truemeans the camera has a flash
- Now you can turn on the flash of the selected camera
cameraManager.setTorchMode (withameraId, true)
Answer 2, authority 33%
Before you start turning on the flashlight itself, you need to pre-register permission to work with it in the manifest:
& lt; permission android: name = "android.permission.FLASHLIGHT" android: permissionGroup = "android.permission-group.HARDWARE_CONTROLS" android: protectionLevel = "normal" android: label = "@ string / permlab_flashlight" android: description = "@ string / permdesc_flashlight" / & gt;
Then the flash is turned on like this:
Camera cam = Camera.open (); Parameters p = cam.getParameters (); p.setFlashMode (Parameters.FLASH_MODE_TORCH); cam.setParameters (p); cam.startPreview ();
There are similar questions: 1 and 2 . In general, not every smartphone is equipped with a front flash, so I think that access to this feature is done separately by the manufacturer through some kind of crutches.