Flashlight Light and Android flashlight light developed based on the android platform
Flashlight Light developed based on Android platform
1. Requirement Analysis:
In modern society, the functions of mobile phones are becoming more and more perfect, and flashlights are essential to these functions. When walking on a dark road, when you are looking for items in a dark and small place, when you have a power outage at home, if your mobile phone has a flashlight function, it will bring you great convenience. Of course, it is not just so useful. With such a portable flashlight, it is of great benefit in many cases. Therefore, the application of flashlight was developed.
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 set version number
4.2Light program structure and permission Configuration
4.4 Light program code
5. Test results:
The Light application basically completes the flashlight function and successfullyGoogle Nexus 4It runs on a real machine, but no more functions have been added due to personal ability reasons, such as the flashlight brightness adjustment function.
Advantages:The method used in the flashlight is relatively simple. For example, the Code for calling the camera flashlight is searched online.
Disadvantages:The flashlight still has many small functions that need to be further improved and the interface can be more beautiful.
6. Q &:
When I wrote this Light application, I encountered a few interesting questions. I recorded and consulted the materials and shared them with you.
6.1:AboutSystem. out. println (e)AndE. Comparison of printStackTrace ()
System. out. println (e)This method prints an exception and outputs an exception;
E. printStackTrace ()It also prints an exception, but it also displays a deeper call Information.
ThereforeE. printStackTrace ()It is to print the stack information of the exception and specify the cause of the error. In fact, when an exception occurs, it is usually necessary to handle the exception. This is a good habit of programming, so e. printStackTrace () can facilitate program debugging.
6.2:How to enable flashlight for Android
① Create a new android. OS package in the project and create an IHardwareService. aidl file with the following content.
Then, call
You must also enable the permission to use the flashlight.
② Use a Camera to control the flashlight, and use Camera's rich interfaces and Parameters,