Android Flashlight principle

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.