The flashlight light developed on Android platform

Source: Internet
Author: User

The flashlight light developed on Android platform

1. Demand Analysis:

In modern society, the function of mobile phones is more and more perfect, flashlight is an essential one of these functions. When walking on the Dark Road, when you are in a dark place to find items, when you are in a power outage at home, if your phone has a flashlight function, it will bring you great convenience. Of course, its usefulness is not only so, with such a handy flashlight, in many cases is a great benefit, so developed a flashlight this application.

2. Development environment:

1. JDK

Ver:jdk-7u4-windows-x64.exe

2. MyEclipse

Ver:2014myeclipse-pro-2014-ga-offline-installer-windows.exe

3. Android SDK

Ver:android-sdk_r18-windows


3. Light Program Virtual machine:


4. Main code Design:

4.1 Setting the version number

4.2Light program structure and permissions configuration


4.4 Light Program code







5. Test results:

The light application basically completes the flashlight function and runs successfully on the Google Nexus 4 , but has not yet added more features, such as the flashlight brightness adjustment function, due to personal ability reasons.

Advantages: The method used in the flashlight is relatively simple, such as calling the camera Flash code is found on the Internet.

disadvantage: The flashlight still has a lot of small functions did not realize, to further improve the improvement, the interface can also be done more beautiful.



6. Q&a:

In the process of writing this light application, I encountered a few interesting questions, I recorded and read the information and share it to everyone

6.1: A comparison of System.out.println (e) and e.printstacktrace ()

System.out.println (E) This method prints out the exception and where the output occurs;

E.printstacktrace () also prints out exceptions, but it also shows deeper invocation information.

So e.printstacktrace () is the stack information to print the exception, indicating the cause of the error, in fact, when an exception occurs, usually to deal with the exception, which is a good habit of programming, so E.printstacktrace () can be convenient for you to debug the program.

6.2: Introduction to several ways to activate Flash on Android

① Create a new package Android.os in the project, create a new Ihardwareservice.aidl file with the following content.


And then call it in the program.


Also open the right to use the Flash

② uses a camera to control the flash, using the camera's own rich interface and parameters parameters,


The flashlight light developed on Android platform

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.