1

I got the following problem,

I have an unity Game which I would like to run. During running the Game, it always lowers screen lighting and switch of after about 2,5 minutes.

I already tried:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

and

PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
        wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
                "MyWakelockTag");
        wakeLock.acquire();

Links:

Android disable screen timeout while app is running

Android Screen Timeout

Programmatically disable screen timeout

But after this, it still switches off as before.

Were there any changes done, in android or are there any other solutions to solve my problem.

Thanks.

Franz
  • 358
  • 6
  • 18
  • 1
    https://developer.android.com/training/scheduling/wakelock – santosh kumar May 11 '18 at 14:55
  • Thanks for the information, but I have tried this already without success. – Franz May 11 '18 at 15:06
  • 1
    You don't want parital wake lock. You want SCREEN_BRIGHT_WAKE_LOCK or FULL_WAKE_LOCK. Partial will keep the CPU on but dim the screen. – Gabe Sechan May 11 '18 at 15:22
  • @Gabe Sechan SCREEN_BRIGHT_WAKE_LOCK and FULL_WAKE_LOCK are deprecated – Franz May 15 '18 at 13:51
  • @GabeSechan Is there some way to hold the wake lock for the screen but release it for the CPU? i.e. "always on screen" that is using minimal battery for AMOLED display but also isn't burning battery by not turning off the CPU which isn't needed? – Michael Jan 22 '19 at 04:56
  • @Michael No there isn't. Mainly because its mostly pointless- the drain from the CPU is dwarfed by the drain from the screen. Screens use more of your battery than everything else combined. Unless you have a weird device with just a eink screen or the like. – Gabe Sechan Jan 22 '19 at 04:57
  • @GabeSechan AMOLED screens are supposed to use next to nothing if you have a nearly totally black (#000000) display - hence why "always on displays" work and only marginally affect your battery life. – Michael Jan 22 '19 at 04:59
  • @Michael They might use less, but not nearly "almost nothing". Its only about half the power of full white. Still more than everything else combined. – Gabe Sechan Jan 22 '19 at 05:00
  • 1
    @Michael Looked at some power diagrams for modern AMOLED displays. It better than the half I stated now, but if its even at 10% luminosity it will be spending about 50mW on the screen. The CPU is in the 10mW range. The only other component that comes close is the radio (30mW in idle mode) and that can't be turned further off without basically killing the connection. And if you want any updates to the app on screen, you'd need to be spinning up the CPU anyway. So yeah, the savings of providing that mode would be minimal, given that it still wouldn't be running the CPU full speed. – Gabe Sechan Jan 22 '19 at 05:12

1 Answers1

1

Solution was very simple done using Unity adding the following Code into the Start() Function:

        Screen.sleepTimeout = SleepTimeout.NeverSleep;

I doesn't know if it is switched of automatically by Unity or nor but I hope so.

Link to Unity Documentation

Franz
  • 358
  • 6
  • 18