Home java Can I call the front camera flashlight on Android?

Can I call the front camera flashlight on Android?

Author

Date

Category

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:

  1. Get a link to CameraManager via cameraManager = (CameraManager) getSystemService (CAMERA_SERVICE);
  2. Get a list of all cameras cameraManager.getCameraIdList ()
  3. Next, go through all the cameras and request cameraManager.getCameraCharacteristics (String cameraId)
  4. In the resulting object of the CameraCharacteristics class, we request the LENS_FACING property, if the property is FRONT , then this is a front camera
  5. Next, request the FLASH_INFO_AVAILABLE property, if true means the camera has a flash
  6. 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.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions