How do I keep the Android screen on?

I don’t know if this has been fixed in 4.9, but I can’t seem to do anything to keep the screen on on UE4 4.8. I have a rolling-ball, tilt-sensor based Android game, so there’s no screen input unless the player has to activate something. I need the screen to stay on even if they don’t touch it. Is there any way to fix this?

Do as described on the answer here. Any text editor (even notepad) can edit a .java file. It’s just plain text.

  1. Find the line where’s written nativeResumeMainInit(); (many text editors have a find function to speed things up);
  2. Create a new line after the one mentioned above and paste AndroidThunkJava_KeepScreenOn(true);
  3. That’s it! =) Save and close and you’re good to go.

I’m not too sure what’s wrong, but this doesn’t work. I placed the text inside, just as your original poster stated, but it does NOT stop the screen from timing out.

Another odd part is, if I go back and check to see if the line is there, it’s been removed. It’s like “GameActivity.java” is getting rewritten everytime I try to compile, removing my alterations.

I’m sorry! I wasn’t notified of your comment!

It’s probably a matter of rights to write the file. If you’re on Windows, open Notepad as Administrator and make the change then save. Close Notepad and open the file again to check. It’ll most likely keep it this time.

That was my first thought, but no, the changes are there… right up until you compile. Then they get rewritten back. I think there’s been a change since the original poster made his comment, because the engine seems to overwrite them now.

Have you personally made this work in 4.8?

Strange. Not actually. I made it in 4.9, though, and it worked everytime after I made the change once.

Try making the file read only after you make the changes to try to figure out WHAT is rewriting it. Something’s gotta crash if it tries to.

I think I figured it out. I was confused on to which file to edit and ended up editing the one in my Unreal Project folder instead of the Engine folder itself. So, of course, it ended up overwriting my changes repeatedly.

After I changed the one in my Unreal Engine folder, I had some weird problems compiling, but 3rd time through it compiled and it appears screen time outs are no longer and issue. Thanks for you time!

##Found this in the forums:

In Blueprint there is a “Control Screensaver” node. Add this with “Allow Screen Saver” checkbox off. From code, use FPlatformMisc::ControlScreensaver(FPlatformMisc::EScreenSaverAction:isable).

Tested and it works! :smiley:

Awesome!! Thank you.