Jeremy Friesner
Jeremy Friesner

Reputation: 73081

How to programmatically dismiss the screensaver/lock screen on Android (Nook Simple Touch)

I wrote a simple alarm-clock style application that I run on my (jailbroken) Nook Simple Touch (aka NST), under Android 2.1.

When the scheduled alarm time arrives, my application needs to wake up the NST and display a page of HTML content. I use AlarmManager to get a callback at the right time, and it seems to work as expected -- almost.

The problem occurs when enough idle time has passed that the NST has activated its lock-screen mode (i.e. it is auto-displaying a caricature of a famous author). I can't find a programmatic way to dismiss the lock-screen so that my HTML content will be visible. I can see that my alarm callback routine ran at the expected time (via the LogCat view in Eclipse, after I reconnect to the NST with adb), and after I manually "drag to unlock" with my finger, I can see that my app's window updated as expected, but I need to have the text become visible when the alarm event occurs, not just after the user unlocks the device. I tried the code shown below (based on other StackOverflow answers) but it doesn't help.

Any ideas regarding a way to do this? (One solution that technically works is to keep FLAG_KEEP_SCREEN_ON set on my window at all times, so that the famous-author-lock-screen never appears in the first place, but that keeps the NST awake and therefore it uses up the battery rather quickly, so I want to avoid that if possible)

private void wakeUpTheScreen()
{
    Window win = getWindow();
    win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
    win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}

Upvotes: 2

Views: 3296

Answers (1)

Jeremy Friesner
Jeremy Friesner

Reputation: 73081

Ha, I figured out (with some more help from previous StackOverflow answers) what I was doing wrong.

The problem is as described in the above link -- the AlarmManager was calling my BroadcastReceiver as expected, and then my BroadcastReceiver would sendMessage() a Message to my AlarmHandler (as shown in the Alarm example I was cribbing from). But the Nook would go back to sleep immediately after onReceive() returned, which meant that the secondary handler never got called, and therefore my wakeUpTheScreen() method wasn't getting executed.

I moved the wakeUpTheScreen() call so that it now gets called directly from the onReceived() method, and now the wakeup works as expected. :^)

Upvotes: 3

Related Questions