سؤال

I am currently making an Android application in which I need the phone to not lock, so as to avoid the activity losing focus.

I have done a bit of research and found numerous ways to do it including the use of:

  • Keyguard Manager
  • Power Manager
  • getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  • android:keepScreenOn="true"

I tried using the android:keepScreenOn="true" in my Android manifest, but it seemed to have no effect on the application. I am hesitant to using power manager as every post about it is filled with numerous warnings.

In closing, what is the best way to prevent the Android phone from locking and losing focus of the application? The screen itself may dim or turn off, so long as the application remains in focus and the phone doesn't lock.

هل كانت مفيدة؟

المحلول

What you want can easily achieved by using the PowerManager with a Screen Dim Wake Lock.

Also, IIRC, keepScreenOn is supposed to be added to a widget in an XML file, not in the manifest, if you do decide to use that in the end.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top