Reputation: 2609
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
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