How to keep screen awake in android mode?

edited January 2016 in Android Mode

I've tried a large variety of methods form other threads, and noticed the hate on WakeLocks, which judging from the way they seem to work is reasonable, but I have not been able to get flags to work, and all the android imports don't seem to do much other than add more errors.

Answers

  • @sparkyjohn===

    something like that i think::

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

  • if I just through that line in, it throws an error:

    1. ERROR in C:\Users****\AppData\Local\Temp\android3153905521260668127sketch\src\processing\test\sleep_clock\Sleep_Clock.java (at line 29) getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); ^^^^^^^^^^^^^ WindowManager cannot be resolved to a variable
  • @sparkyjohn===

    of course, you have to make an import for that::

    import android.view.WindowManager;

  • edited January 2016

    The errors windows tells me that "only a type can be imported. android.view.WindowManger resolves to a package. And since other stuff about functions and classes not existing. Thank you so much for your patience by the way.

  • @sparkyjohn===

    Some kind of bug: It is NOT a package, this message is stupid; try to save && restart, who knows???

  • Now it's telling me that "The funcition 'getActvity()' does not exist"

  • @sparkyjohn===

    yes,i know, another bug:: it does not exist but it works, as you are in a fragment...

  • edited January 2016

    I put it in the setup of the program, is that not what I was supposed to do? And as side note, how would one cancel the flag? Would it be getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_OFF); ?

  • Answer ✓

    @sparkyjohn===

    no, in order to remove use clearFlags() instead of addFlags() as for the other point i am not sure for Processing, it could be in setup() but also in onCreate() or in onCreateView(), you have to try...

Sign In or Register to comment.