Luis A. Florit
Luis A. Florit

Reputation: 2609

Dissable_keyGuard flag not working

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!

Upvotes: 0

Views: 965

Answers (1)

Ifor
Ifor

Reputation: 2835

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);

Upvotes: 1

Related Questions