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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:23:00+00:00 2026-05-24T18:23:00+00:00

I am working on Turning ON/OFF Camera flashlights. What i want to do is

  • 0

I am working on Turning ON/OFF Camera flashlights.

What i want to do is :

  1. When user clicks on Start LED button, it should start the Camera LED.
  2. Stop camera LED automatically after n Seconds eg. after 30seconds (Thats totally based on user settings).
  3. Stop Camera LED when user presses “Stop LED” Button

I have used ToggleButton for Starting and Stopping Camera LED.

Here is what i have done :

 toggleLED.setOnClickListener(new OnClickListener() {  
            public void onClick(View v) {      

                if (toggleLED.isChecked())
                {
                    startLED();
                }
                else      
                {
                    stopLED();
                }
            }
        });

So far i got success in turning ON and OFF Camera Lights.

For Turning On :

void startLED(){
    Camera cam;
    cam = Camera.open();     
    Parameters params = cam.getParameters();
    params.setFlashMode(Parameters.FLASH_MODE_ON);
    cam.setParameters(params);
    cam.startPreview();
    cam.autoFocus(new AutoFocusCallback() {
                public void onAutoFocus(boolean success, Camera camera) {
                }
     });
}

For Turning OFF :

void stopLED() {
    cam.stopPreview();
    cam.release();
}

ToggleButton’s function is working fine.

But what i want is :
How can i shut off Camera Lights after n Seconds ?

Edited:

I tried using this & it completely works fine..But i want to know whether i am going in a correct way or not..

 Runnable r = new Runnable()
              {
                  public void run()
                  {
                      stopLED();                  

                  }
              };


toggleLED.setOnClickListener(new OnClickListener() {  
            public void onClick(View v) {      
                // Perform action on clicks     



                if (toggleLED.isChecked())
                {
                    startLED();                 

                    int onledseconds=pref.getInt(MySettings.SHUTOFF_PERIOD,0);                  

                    if(onledseconds!=0)
                        handler.postDelayed(r,ledonseconds);
                }
                else      
                {

                    stopLED();
                }
            }
        });      
  • 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-24T18:23:01+00:00Added an answer on May 24, 2026 at 6:23 pm

    I tried using this & it completely works fine..But i want to know whether i am going in a correct way or not..

    Runnable r = new Runnable()
    {
       public void run()
       {
          stopLED();                  
       }
    };
    toggleLED.setOnClickListener(new OnClickListener() {  
      public void onClick(View v) {      
        // Perform action on clicks     
        if (toggleLED.isChecked())
        {
           startLED();                 
           int onledseconds=pref.getInt(MySettings.SHUTOFF_PERIOD,0);                  
           if(onledseconds!=0)
           handler.postDelayed(r,ledonseconds);
        }
        else      
        {
          stopLED();
        }                     
      }
    }); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working with the Smarty Template Engine with display_errors = Off . Turning
I'm working on an iOS app where I use third party libraries. I want
I am working on a complex spreadsheet based solution. Occasionally a user will experience
I am currently working on turning a normal html table like so: into and
I’m getting a funny error after I deploy a fully working symfony project to
i have attempted to follow the advice at SF for turning off objective-C arc
I am working on performance tuning of a java rmi application and using OQL
I'm working on SQL SERVER 2008 R2 Performance tunning part but I'm new in
I’m working on a experiment regarding to a course I’m taking about tuning DB2.
Working on a small game using an HTML5 canvas, and javascript. And it's working

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.