0

All,

I've seen other threads on this and I know the solution. Question here is why following line of code doesn't work on Android 4.4.2 API 19? The code doesn't error out. But it doesn't not make the device's screen to keep on. I am trying to do this from a widget. So I can't do other suggested solutions for using android:keepScreenOn or using getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Anyone who is answering please test following line on actual Android devices like Nexus 5 OR Nexus 7. It does not keep the screen on. It works fine on devices with API < 19.

android.provider.Settings.System.putString(getContentResolver(),android.provider.Settings.System.SCREEN_OFF_TIMEOUT, "-1");

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
N.S.
  • 269
  • 3
  • 9

1 Answers1

0

If you want to keep the screen on all the time just use: getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Already answered here

Community
  • 1
  • 1
Emil Borconi
  • 3,326
  • 2
  • 24
  • 40
  • That only works with activity. I need to do this through widget. – N.S. Feb 12 '14 at 22:00
  • Ok, widget wasn't mentioned. Your piece of code worked just fine on my CM11 test device, so are you really sure there isn't something else missing? As a fallback you can always use the wakelock solution http://stackoverflow.com/questions/8442079/keep-the-screen-awake-throughout-my-activity – Emil Borconi Feb 12 '14 at 23:12
  • Were you trying on Android 4.4.2? This code works fine on device with API < 19. But it doesn't work on devices with API 19 – N.S. Feb 13 '14 at 18:44
  • Yes i tested it on my Relay, running 4.4.2 – Emil Borconi Feb 13 '14 at 18:48
  • Does the screen remain ON after you set it? The code doesn't error out or anything. It just does not keep the screen ON. I tested it out on actual Nexus 7 and Nexus 5 device. My alternate solution to this is to use WakeLock but I an curious to know why "-1" does not work with Android 4.4.2. – N.S. Feb 13 '14 at 19:00
  • I tested it as an app not as a widget and it did worked nicely, I don't know why is the -1 it's not from me. – Emil Borconi Feb 13 '14 at 19:17
  • I also tried from an activity instead from widget and deployed my app on Nexus 7 2013 and after clicking button on my app, Screen shuts off in few seconds. I am not sure if this is only isolated to Nexus devices. Also when you test on emulator or any of your device make sure that 'Stay Awake' option is deselected on Developers Options – N.S. Feb 13 '14 at 20:42