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

I want the Android device to wake up from sleep or, nevertheless, a state in which the phone gets a certain amount of inactivity when the screen goes dark by detecting a touch on the screen, rather than pressing any button.

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

Window check box: if set, if the device is sleeping 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 cannot see what they are clicking.

I thought that means that if the device’s screen is turned off and this flag is set to Activity, it will wake up to the touch (this is exactly what I want to do). Do I really not understand the purpose of this flag? Are there any additional implementation details that I ignore? Is there another way?

+6
source share
1 answer

I do not understand the purpose of this flag?

AFAIK, yes. There is from time to time when the screen turns off and when the device falls asleep. During this time, if the user touches the screen somewhere where the window has this flag, the screen turns on again and the inactivity timer is reset.

I cannot find another use of this flag in the Android source code.

Is there another way?

Not. If the device is sleeping, touch screen events are not logged.

+4
source

Source: https://habr.com/ru/post/887476/


All Articles