--ADVERTISEMENT--

Android allows us to access the camera LED/ Flashlight/ Touchlight in our application. You can turn ON and OFF flashlight from your application using java code. Most of the time android flash light is on while taking photos in flash mode. In this tutorial, you will learn how to turn ON and OFF camera LED/ flashlight programmatically from your android app.

To work with android flashlight/touch light, you have to add the permission to access camera and hardware in your application AndroidManifest.xml file.

This is simple turn on and off flashlight android application; here is no any complex code you just have to add little bit java code. Here, I have used toggle button to turn on and off flashlight.

Related:
Turn ON and OFF WiFi Connection Programmatically in Android
Android ToggleButton and Switch Button Example
Android CheckBox Example

Android Example: Turn On and Off Camera LED / Flashlight Programmatically


Following is the step by step guide to turn on/off flashlight programmatically in android.


Create a new Android Project


Let’s start by creating a new project to turn on/off camera led/flashlight programmatically with following information.

Application name: Turn On and Off Android Flashlight
Company Domain: viralandroid.com
Package name: com.viralandroid.turnonandoffandroidflashlight

Adding Permission


Open your app AndroidManifest.xml file and add android.permission.CAMERA and android.hardware.camera permission. AndroidManifest.xml file will looks like this.

AndroidManifest.xml


XML Layout File


Following is the content of XML layout file where I have added a toggle button to turn on and off flash light programmatically from android app.

res/layout/turn_on_off_camera_flash_light.xml


Java Activity File


Following is the simple java code to develop android flash light application.

src/ OnOffCameraFlashlight.java

Strings.xml File


res/values/strings.xml

Android Example: Turn On and Off Camera LED / Flashlight Programmatically

That’s all. Now run your Turn On and Off Camera LED / Flashlight Programmatically in Android application and click the toggle button to turn on and off flashlight of your phone. Make sure to work by this example, your device should have the flash light.

Post a Comment

  1. The Led Flashlight and fire maker is among the most important items to bring along when you go to the jungle either for camping,Led Flashlight come in a variety of different colors. How do you know what to use them for? This article describes how different colored Led Flashlight in flashlights can be used for different applications.

    ReplyDelete

Powered by Blogger.