'Android - how to turn off screen for few hours and then turn it on again?
I have an Android TV box (Android 9) and a connected screen via HDMI. What I want to do is to programatically turn off the screen and then (after few hours) wake up the screen again.
I use react-native-idle-timer to turn off the screen (it just sets or removes WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON).
This works perfectly to turn off the screen (the FLAG_KEEP_SCREEN_ON is removed from the activity and then the screen goes to sleep in few minutes).
The issue is waking up the screen.
It looks like that if the device is "sleeping" more than X minutes, it is not possible to wake it up anymore (probably because the app is somehow suspended / cpu stops?). To wake up the app, I use react-native-android-wake-screen, which uses this to wake up the screen:
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "yourApp:tag");
wakeLock.acquire();
and I have this in the app's manifest:
<uses-permission android:name="android.permission.WAKE_LOCK" />
Do you have any idea how to make this work?
I have few ideas but not sure if they are suitable:
- somehow tell the system to never "suspend" the app (maybe setting
PARTIAL_WAKE_LOCKfor the time the device should be sleeping?) - set up an alarm that would wake up the device at specified time (and wake up the screen)
Thanks for any help
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
