Prevent screen form going black on android

Hey,

Is there an existing solution on how to prevent the screen from going black on android? I found this thread, but the links do not work anymore:

http://www.openfl.org/archive/community/programming-haxe/how-prevent-auto-locksleep-android-ios/

Thanks!
Nathan

Looks like there’s some details here:

https://developer.android.com/training/scheduling/wakelock

I’d love suggestions on where/how we support something like this in the Lime API

You shouldn’t use wakelock just to keep screen on, also lime already has code that prevents auto-lock:

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

In my games developed for android on java I simply use android:keepScreenOn="true" in layout, which is equal to WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON

Do I understand correctly? Lime is already taking care of it? But my screen IS going black after about half a minute.
Do I have to enable this somehow?

It seems that it is only in legacy code, so 1) you must use -Dlegacy, 2) fullscreen=“true” must be set for window and 3) ANDROID_TARGET_SDK_VERSION should be less than 19

If it didn’t help, please show me what is under export/android/bin/src/org/haxe/lime/GameActivity.java


::if WIN_FULLSCREEN::
    ::if (ANDROID_TARGET_SDK_VERSION < 19)::
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
            | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    ::end::
::end::

That’s strange, both FLAG_FULLSCREEN and FLAG_KEEP_SCREEN_ON is available even on API 22. @singmajesty What do you think about it?

Thanks, for now it is fixed for me. I have edited the file GameActivity.java in my lime install to add the flag even if the SDK version is above >19.

This must have been related to a change in order to handle Android fullscreen without showing the on-screen buttons, FLAG_KEEP_SCREEN_ON was an unfortunate casualty, but perhaps we should use an AndroidManifest.xml way of doing this (straight up single option) or go completely the route of making this a runtime configurable option