tags:

views:

130

answers:

2

Hi,

my app does something when the screen goes black, but I want it to only carry out that task if the screen was turned off "by itself", through a screen timeout - NOT when the user presses the power-button. Is there any way to distinguish between these two events?

ACTION_SCREEN_OFF obviously fires in both cases, and I haven't found any other intents that might match what I'm looking for.

Thanks for your help, Nick

A: 

Can you listen for a KEYCODE_POWER keyboard event? That might do what you want. (But the order in which that and ACTION_SCREEN_OFF arrive might not be guaranteed).

jimrandomh
Hi, thanks for the answer! That's a good idea, although I just tried it and it doesn't work, it doesn't seem possible to catch that keycode: http://groups.google.com/group/android-developers/browse_thread/thread/8c858b7a8605791d/9120aa96dfb59d82?lnk=raotAlso, I would need to register that key-event system-wide because I'm using a service, which is also not possible, I think :-/But thanks for your help, it's a good idea, if it worked, it would have been perfect :-)!
Nick
+1  A: 

At the lower level there's an event happening when the screen times out, take a look with "adb logcat" and you'll see it, dig from there.

Berkus
Thanks for your answer. I saw that, but thought that since it's not a public broadcast, I couldn't listen for it, but I'm sure I'll find something on that on google if you say that it is theoretically possible (although not with common means, I guess). Thanks!
Nick