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

  • Home
  • SEARCH
  • 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 6822245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:38:24+00:00 2026-05-26T21:38:24+00:00

since i’m at the beginning with Android coding i hesitated to post my question,

  • 0

since i’m at the beginning with Android coding i hesitated to post my question, but now i’m at the point where i can’t resist.

I have a service which turns on the camera-LED onCreate:

@Override
public void onCreate() {
// make sure we don't sleep
this.pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
this.mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "SleepLED");

    this.mTimer = new Timer();
    this.mTimerTask = new TimerTask() {
        public void run() {
        // turn on the LED
        setFlashlight(Camera.Parameters.FLASH_MODE_TORCH);

        mWakeLock.acquire();
        }
    };

    // Get the notification-service
    this.mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
    // Display a notification about us starting.  We put an icon in the status bar.
    showNotification();

    // Open camera
    this.frontCam = Camera.open();
    this.frontCamPara = frontCam.getParameters();
    this.frontCam.lock();


    // Schedule the TimerTask
    this.mTimer.schedule(mTimerTask, 0);
}

I can tell that the WakeLock acquires, I tested with FULL_WAKE_LOCK and it didn’t turn off considering Screen Time-Out.
But since the Screen isn’t need to be on I don’t want to use the full wakelock.

The Cyanogenmod for my phone (HTC Legend) brings an torch-app which can do what i want.
Its source code is here:
https://github.com/CyanogenMod/android_packages_apps_Torch/tree/gingerbread/src/net/cactii/flash2
I noticed that the light turns off for a short moment with that app, if this is a hint for someone, obviously not for me ;(

I don’t expect someone to change my code to do what i want
but I’d be thankful if anyone could point me in the right direction!

Greets
SJ

  • 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-26T21:38:25+00:00Added an answer on May 26, 2026 at 9:38 pm

    I have found a solution to the problem.
    When the phone turns off the screen it does deactivate the camera LED, but it allows a user to reactivate it like this:

    @Override
    public void onCreate() {
        // assume we start with screen on and save that state ;-)
        this.pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        screenOn = this.pm.isScreenOn();
    
        // program a timer which checks if the light needs to be re-activated
        this.mTimer = new Timer();
        this.mTimerTask = new TimerTask() {
            public void run() {
                // re-activate the LED if screen turned off
                if(!pm.isScreenOn() && pm.isScreenOn() != screenOn) {
                    Log.i("SleepLEDservice", "re-activated the LED");
    
                    // really it's NOT ENOUGH to just "turn it on", i double-checked this
                    setFlashlight(Camera.Parameters.FLASH_MODE_OFF);
                    setFlashlight(Camera.Parameters.FLASH_MODE_TORCH);
                }
                screenOn = pm.isScreenOn();                 
            }
        };
    }
    
    private void setFlashlight(String newMode) {
        try {
            this.frontCamPara = this.frontCam.getParameters();
            if(this.frontCamPara.getFlashMode() != newMode) {
                this.frontCamPara.setFlashMode(newMode);
                this.frontCam.setParameters(frontCamPara);  
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    

    The key is changing the state back to FLASH_MODE_OFF and than back to FLASH_MODE_TORCH.

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

Sidebar

Related Questions

since last post, did all the changes suggested but this problem still haunts me.
Since CS3 doesn't have a web service component, as previous versions had, is there
Since i'm not strong in asp.net, probably my question will sound silly. I've got
Since I've known about Node.js, I've always been a fan of it. But today
Since in the control file I have to provide a name (hard-coded) I need
Since I'm new to coding and I'm trying to understand why here is a
Since i discovered the concept of non-blocking scripts i have become obsessed with loading
Since I already have a mobile phone (and contract), I bought a droid X
Since debate without meaningful terms is meaningless , I figured I would point at
Since Java char is 16 bit long, I am wondering how can it represent

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.