Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5955115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:04:05+00:00 2026-05-22T18:04:05+00:00

I want to turn on front flash light (not with camera preview) programmatically in

  • 0

I want to turn on front flash light (not with camera preview) programmatically in Android. I googled for it but the help i found referred me to this page

Does anyone have any links or sample code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:04:05+00:00Added an answer on May 22, 2026 at 6:04 pm

    For 2021, with CameraX, it is now dead easy: https://stackoverflow.com/a/66585201/294884


    For this problem you should:

    1. Check whether the flashlight is
      available or not?

    2. If so then Turn Off/On

    3. If not then you can do whatever, according to your app
      needs.

    For Checking availability of flash in the device:

    You can use the following:

     context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
    

    which will return true if a flash is available, false if not.

    See:
    http://developer.android.com/reference/android/content/pm/PackageManager.html for more information.

    For turning on/off flashlight:

    I googled out and got this about android.permission.FLASHLIGHT. Android manifests’ permission looks promising:

     <!-- Allows access to the flashlight -->
     <permission android:name="android.permission.FLASHLIGHT"
                 android:permissionGroup="android.permission-group.HARDWARE_CONTROLS"
                 android:protectionLevel="normal"
                 android:label="@string/permlab_flashlight"
                 android:description="@string/permdesc_flashlight" />
    

    Then make use of Camera and set Camera.Parameters. The main parameter used here is FLASH_MODE_TORCH.

    eg.

    Code Snippet to turn on camera flashlight.

    Camera cam = Camera.open();     
    Parameters p = cam.getParameters();
    p.setFlashMode(Parameters.FLASH_MODE_TORCH);
    cam.setParameters(p);
    cam.startPreview();
    

    Code snippet to turn off camera led light.

      cam.stopPreview();
      cam.release();
    

    I just found a project that uses this permission. Check quick-settings’ src code. here http://code.google.com/p/quick-settings/ (Note: This link is now broken)

    For Flashlight directly look http://code.google.com/p/quick-settings/source/browse/trunk/quick-settings/#quick-settings/src/com/bwx/bequick/flashlight (Note: This link is now broken)

    Update6
    You could also try to add a SurfaceView as described in this answer LED flashlight on Galaxy Nexus controllable by what API?
    This seems to be a solution that works on many phones.

    Update 5 Major Update

    I have found an alternative Link (for the broken links above): http://www.java2s.com/Open-Source/Android/Tools/quick-settings/com.bwx.bequick.flashlight.htm You can now use this link. [Update: 14/9/2012 This link is now broken]

    Update 1

    Another OpenSource Code :
    http://code.google.com/p/torch/source/browse/

    Update 2

    Example showing how to enable the LED on a Motorola Droid: http://code.google.com/p/droidled/

    Another Open Source Code :

    http://code.google.com/p/covedesigndev/
    http://code.google.com/p/search-light/

    Update 3 (Widget for turning on/off camera led)

    If you want to develop a widget that turns on/off your camera led, then you must refer my answer Widget for turning on/off camera flashlight in android.

    Update 4

    If you want to set the intensity of light emerging from camera LED you can refer Can I change the LED intensity of an Android device? full post. Note that only rooted HTC devices support this feature.

    ** Issues:**

    There are also some problems while turning On/Off flashlight. eg. for the devices not having FLASH_MODE_TORCH or even if it has, then flashlight does not turn ON etc.

    Typically Samsung creates a lot of problems.

    You can refer to problems in the given below list:

    Use camera flashlight in Android

    Turn ON/OFF Camera LED/flash light in Samsung Galaxy Ace 2.2.1 & Galaxy Tab

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a console application, but I want to turn it into a windows
I want to turn a program I have into a service so I can
I want to turn off PHP's magic quotes. I don't have access to php.ini.
I want to turn something like this CS 240, CS 246, ECE 222, ...
dev%40bionic%2Dcomms%2Eco%2Euk I want to turn the above back in to readable text. Can anyone
I have a control that I'm writing where I want to turn off .NET's
I have a set of points that i want to turn into a closed
I have a list of objects which I want to turn into a set.
I made an MFC application, and now i want to turn off the window's
I have the following array, $myarray[0]['first_name'] $myarray[0]['last_name'] I want to turn it into: $myarray['first_name']

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.