Android flashlight Principle

Source: Internet
Author: User

Android flashlight Principle

I. Principles

Currently, the android app store has many flashlight applications. Its core principle is very simple. In fact, it is to use the Camera in android to control the flashing. Now, Let's explain how android controls the flashlight step by step.

2. Add Permissions

When using android camera, you must first add the android permission to control camera in the AndroidManifest. xml file.

 
   
 
 
 

What are these permissions for? For details, refer to my blog.

Http://blog.csdn.net/stoppig/article/details/20458865

Iii. Control Code

After the flash control is added, you can write the code for controlling the flash.

1. Open the camera and turn on the flashlight.

Before using the flashlight, use the Camera. open () method to open the camera and obtain the Camera object. Then the Parameters parameter is obtained through the getParameters () method of the camera object. The following is the sample code.

Camera = Camera. open (); parameters = camera. getParameters (); parameters. setFlashMode (Parameters. FLASH_MODE_TORCH); // enable camera. setParameters (parameters );

2. Turn off the flashlight and camera

When the flashlight is turned off, it is also set through the Parameters parameter. Set the FlashMode variable of Parameters to Parameters. FLASH_MODE_OFF, and then close the camera. The following is the sample code.

Parameters. setFlashMode (Parameters. FLASH_MODE_OFF); // disable light. setImageResource (R. drawable. light_off); camera. setParameters (parameters); camera. release ();

This is a simple android flashlight code description.

Source code: http://download.csdn.net/detail/stop_pig/8102453

Related Article

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.