3

I need to disable lockscreen and set screentimeout to never not only in my app but for the phone generaly.

I tried to set the screentimeout to "-1", which worked e.g. on Android 2.3 but not on 4.2 Is there any way to do so?

Settings.System.putString(context.getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, "-1");
PetrD
  • 45
  • 1
  • 5

2 Answers2

0

Wasn't able to check on 4.2 but the same code worked fine on 4.1.2 as long as I added the following permission -

    <uses-permission android:name="android.permission.WRITE_SETTINGS"/>
user1721904
  • 843
  • 4
  • 13
  • Thanks for reply. I already have this in my manifest. I didn't test 4.1.2 but on 4.2 this solution doesn't work. – PetrD Feb 24 '13 at 11:20
-1

You can do it in the xml layout file of each activity by adding Android:screenOn="true"

Snake
  • 14,228
  • 27
  • 117
  • 250
  • I need this for the whole phone (other apps included) not just for my activities, thanks for reply thought. – PetrD Feb 24 '13 at 11:21
  • Then you can do it using a wakeLock service. I didn't use it but is used for keeping phone awake. Here is a link for you http://stackoverflow.com/questions/14128126/service-wakelock – Snake Feb 24 '13 at 21:45
  • It is `android:keepScreenOn="true"` – keaukraine Aug 07 '13 at 15:07