Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get a device to wake up from sleep (screen dark) by detecting a touch to the screen?

Tags:

android

I want to get an android device to wake up from sleep or however the state in which the phone gets after a certain amount of inactivity when the screen goes dark, by detecting a touch to the screen instead of clicking on any button.

In the documentation the only thing I have found is the FLAG_TOUCHABLE_WHEN_WAKING flag in WindowManager.LayoutParams and it says:

Window flag: When set, if the device is asleep when the touch screen is pressed, you will receive this first touch event. Usually the first touch event is consumed by the system since the user can not see what they are pressing on.

I thought that meant that if the device's screen is turned off and that flag is set for an Activity then it will wake up to the touch (which is what I want it to do). Am I misunderstanding the purpose of this flag? Are there additional implementation details I'm ignoring? Is there some other way?

like image 637
bluediapente Avatar asked May 06 '11 18:05

bluediapente


1 Answers

Am I misunderstanding the purpose of this flag?

AFAIK, yes. There is a slice of time between when the screen turns off and when the device falls asleep. During this time, if the user touches the screen someplace where the window has this flag, the screen turns on again and the inactivity timer is reset.

I can find no other use of this flag in the Android source code.

Is there some other way?

No. If the device is asleep, touch screen events are not registered.

like image 83
CommonsWare Avatar answered Sep 18 '22 05:09

CommonsWare