- Home /
Prevent android device from sleeping ?
Hi, I am using this code to prevent the phone from sleeping (Black screen),
Screen.sleepTimeout = SleepTimeout.NeverSleep;
But this still doesn't work in some devices. Am I doing it right ???
Please help.
Answer by Sisso · Jun 02, 2014 at 07:13 PM
Yes, use sleepTimeout is the "right" way the device from sleeping. With devices that I tested (both android and ios) it works correctly (on Unity 4.2).
Create some script to dump the current value to check if is setting correctly and nobody is changing.
If the device that is not working is android could have a chance of a bad implementation from the manufacturer (they suck in programing :P).
Thanks for quick reply.
Well, I am using admob interstitials, When the interstitial shows up, the phone goes to sleep mode no matter what.
I have tried everything,
Application.runInBackground = true;
Screen.sleepTimeout = SleepTimeout.NeverSleep;
Adding this permission in the Android$$anonymous$$anifest.xml ->
still no luck :(
please help.
Adding the permission for the WA$$anonymous$$E_LOC$$anonymous$$ is not enough. You need to invoke it.
Screen.sleepTimeout = (int)SleepTimeout.NeverSleep; in my case, it's worked good.