I. Introduction of the principle
Now the Android App Store has a lot of flashlight apps. The core principle is very simple, in fact, using the camera-type cameras in Android control the flash lights. OK, next, step-by-step tutorial on how Android controls the Flash.
Second, add permissions
When using the Android camera, the first step is to add Android control to the camera in the Androidmanifest.xml file.
<uses-permission android:name= "Android.permission.FLASHLIGHT"/> <uses-permission android:name= " Android.permission.CAMERA "/><uses-feature android:name=" Android.hardware.camera "/><uses-feature Android:name= "Android.hardware.autofocus"/>
This several permissions is what to use, specific instructions, you can refer to my blog.
http://blog.csdn.net/stoppig/article/details/20458865
Third, control code
Once added, you write code that controls the flash.
1. Turn on the camera and turn on the flash
Before using the flash, be careful to use the Camera.open () method to open the camera and get to the camera object. The parameters parameter is then obtained through the camera object's GetParameters () method. Here is the sample code
Camera = Camera.open ();p arameters = Camera.getparameters ();p Arameters.setflashmode (parameters.flash_mode_torch);// Open camera.setparameters (parameters);
2. Turn off the flash and turn off the camera
When the flash is turned off, it is also set by the parameters parameter, first set the parameters Flashmode variable to Parameters.flash_mode_off, and then turn off the camera. Here is the sample code
Parameters.setflashmode (Parameters.flash_mode_off);//Close Light.setimageresource (R.drawable.light_off); Camera.setparameters (parameters); Camera.release ();
This is a simple Android flashlight code description.
Source: http://download.csdn.net/detail/stop_pig/8102453
Android Flashlight principle