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 7923783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:25:38+00:00 2026-06-03T17:25:38+00:00

So I’m trying to have a button where users can choose between flash on/off/auto.

  • 0

So I’m trying to have a button where users can choose between flash on/off/auto. This button is within my camera preview activity, but I’m not sure how to check certain parameters with one button.

    //Flash Button
    final Button flashButton = (Button) findViewById(id.camera_flash);
    flashButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if(mCamera != null){
                Parameters p = mCamera.getParameters();
                p.setFlashMode(Parameters.FLASH_MODE_AUTO);
                mCamera.setParameters(p);
                mCamera.startPreview();
                flashButton.setText("AUTO");
                Log.e("Torch","Torch On");
            }else{
                Parameters p = mCamera.getParameters();
                p.setFlashMode(Parameters.FLASH_MODE_OFF);
                mCamera.setParameters(p);
                mCamera.release();
                mCamera=null;
                flashButton.setText("OFF");

            }// maybe another one for ON



        }

Right now its setting if mCamera!=null but then how do I check if flash is AUTO, ON, or OFF? I’m thinking that there maybe a SWITCH instead? I’m trying to keep these settings in one button, so its kind of a toggle. Can someone help me with this?

Thanks in advance.

UPDATED CODE

   //Flash Button
    final Button flashButton = (Button) findViewById(id.camera_flash);
    flashButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Parameters p = mCamera.getParameters();

            // TODO Auto-generated method stub
            if(p.getFlashMode() == android.hardware.Camera.Parameters.FLASH_MODE_ON){
                p.setFlashMode(Parameters.FLASH_MODE_OFF);
                mCamera.setParameters(p);
                mCamera.startPreview();
                flashButton.setText("Off");
                Log.e("Torch","MODE OFF");

            }else if(p.getFlashMode() == android.hardware.Camera.Parameters.FLASH_MODE_OFF){
                p.setFlashMode(Parameters.FLASH_MODE_TORCH);
                mCamera.setParameters(p);
                mCamera.release();
                mCamera=null;
                flashButton.setText("TORCH");
                Log.e("Torch","MODE TORCH");

            }else if(p.getFlashMode() == android.hardware.Camera.Parameters.FLASH_MODE_AUTO){
                p.setFlashMode(Parameters.FLASH_MODE_ON);
                mCamera.setParameters(p);
                mCamera.startPreview();
                flashButton.setText("ON");
                Log.e("Torch","MODE ON");

            }else if(p.getFlashMode() == android.hardware.Camera.Parameters.FLASH_MODE_TORCH){
                p.setFlashMode(Parameters.FLASH_MODE_ON);
                mCamera.setParameters(p);
                mCamera.startPreview();
                flashButton.setText("AUTO");
                Log.e("Torch","MODE AUTO");

            }else{
                p.setFlashMode(Parameters.FLASH_MODE_AUTO);
                mCamera.setParameters(p);
                mCamera.startPreview();
                flashButton.setText("AUTO");
                Log.e("Torch","MODE AUTO");

            }



        }
  • 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-06-03T17:25:39+00:00Added an answer on June 3, 2026 at 5:25 pm

    You can check if flash is AUTO, ON, or OFF as:

    Camera.Parameters p= mCamera.getParameters();
    
    if(p.getFlashMode().equals(android.hardware.Camera.Parameters.FLASH_MODE_ON))
    {
     //DO STUFF...
    }
    else if(p.getFlashMode().equals(android.hardware.Camera.Parameters.FLASH_MODE_OFF))
    {
    //DO STUFF......
    }
    else if(p.getFlashMode().equals(android.hardware.Camera.Parameters.FLASH_MODE_TORCH))
    {
    //DO STUFF......
    }
    else if(p.getFlashMode().equals(android.hardware.Camera.Parameters.FLASH_MODE_AUTO))
    {
    //DO STUFF......
    }
    else
    {
    //DO STUFF.....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
Thanks in advance for your help. I have a need within an application to
I am trying to understand how to use SyndicationItem to display feed which is

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.