0

I'm trying to disable screen lock. I want the screen to go off after timeout, but to go on again with my app when touched.

Since keywardlock is deprecated, I tried the following in onCreate():

    final Window win = getWindow();
    win.setFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED,
            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

Just in case, I added the following in the manifest (is this needed??):

<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.FLAG_SHOW_WHEN_LOCKED" />

Still, after my usual timeout, the screen is locked...

What am I doing wrong?? Thanks!

Luis A. Florit
  • 2,169
  • 1
  • 33
  • 58

1 Answers1

1

SetFlags takes the flags and a mask you are not using it that way. The easyest thing is to use the helper method addFlags I am using the following code.

  Window window = getWindow();
  window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
  window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
Ifor
  • 2,825
  • 1
  • 22
  • 25
  • I see what I was doing wrong, thanks. However, your suggestion only works partially. While I don't need a gesture to unlock the screen with your suggestion, I still need to press the middle bottom button of the phone. I tried adding FLAG_KEEP_SCREEN_ON, but then the screen does not turns off at all. I want the screen to turn off, but to wake up when touching it (not the middle bottom button). Maybe this is not possible...? – Luis A. Florit Nov 21 '12 at 00:30
  • I don't belive that's possible. The touch sensor is only powered up when the screen is powered up. I have to hit a hard button to wake things up but I then go straight back to my app. if you do find out how to do it I would like to know.... – Ifor Nov 21 '12 at 09:07
  • I understand. Related to this is the partial wakelock. I was not able to make it work on a Galaxy Note (ICS), only full wakelock seems to work. – Luis A. Florit Nov 21 '12 at 20:14