SoFunction
Updated on 2025-03-11

How to control flash on Android (on and off)

This article describes the method of controlling flash on Android. Share it for your reference, as follows:

I want to make a flashlight recently and I found some information online

First of all, the flash can be used to control it

1. Add permissions to the file

Copy the codeThe code is as follows:
<uses-permission android:name="" />

2. Turn on the flash

try{
  m_Camera = ();
   mParameters;
  mParameters = m_Camera.getParameters();
  (.FLASH_MODE_TORCH);
  m_Camera.setParameters(mParameters);
} catch(Exception ex){}

3 Turn off the flash

try{
   mParameters;
  mParameters = m_Camera.getParameters();
  (.FLASH_MODE_OFF);
  m_Camera.setParameters(mParameters);
  m_Camera.release();
} catch(Exception ex){}

In Android, to turn on the camera, you can simply turn on through it. After turning on it, you can set parameters

The flashlight function we need is just set to FLASH_MODE_TROCH to turn off. Just set it to FLASH_MODE_OFF and release it

Don't forget to call release() when the application terminates to terminate the program

For more information about Android development, readers who are interested in reading the topic of this site:Android development introduction and advanced tutorial

I hope this article will be helpful to everyone's Android programming design.