Keep the screen on in Trusted Web Activity

39 Views Asked by At

I want to keep screen on while show trusted tabs. I was override the WebViewFallbackActivity class and inject this code but it's not working:

PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WakelockTag");
wakeLock.acquire(10 * 60 * 1000L);

is there any solution to do this? Thanks.

1

There are 1 best solutions below

0
andreban On

There is a solution for this!

You need to use the web WakeLock API instead. I've used it in https://doom-fire.com/, and you can keep the screen on by clicking on the padlock icon. You can check the code my implementation here.