Turn On / Turn Off your Phone’s Flash Light

Turn On / Turn Off your Phone’s Flash Light

To be very honest I didn’t know where the Flash Button was , I noticed it was after you turn on the flash option on your Camera Settings. So I decided to make a button which when clicked turned on/off the flash light depending on the status. I also thought it’ll be interesting if you could send an SMS to your phone with some command i.e “Turn On” and the phone does just that.


  1. Basic UI Design (By basic I mean drag and drop )
  2. Basic Java Knowledge

XML Layout

Open your Android Studio and create a blank project , you can name it whatever you want. Add two buttons on the xml layout . Here is how I did mine , I could have simply used one button but for simplicity I had two buttons

The flashlight is provided by the Android Camera API , it has interfaces that allows you to have your own implementation of how the camera should work. We are required to ask for permission before we are able to initiate such hardware requests. Be sure to declare your permissions at the Android Manifest File. The new versions of Android requires you do the same while on Run-time. Put up the following in your Manifest File.

Also on your Activity ask for the permissions.

He’s the fun part now, add listeners to the two buttons you created.

Have functions which when called turns on the flash light and switches it off depending on the context.

To maintain the state of the buttons , you can make use of Visibility Option in Android’s UI Elements. For instance if the user clicks the “Turn On” button it makes the button disappear and show the “Turn Off” and vice-versa.

Viola , you are now able to Turn On and Off your Phone’s Flash Light. Get the Code on my Github here : https://github.com/brianosoro/FlashLight-App

Comment / Critic / Share



2 Replies to “Turn On / Turn Off your Phone’s Flash Light”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.