Reputation: 2594
As the title says, I've been surprised to find that FLAG_DISMISS_KEYGUARD flag is no longer functioning on API 21 (Lollipop).
In kitkat, setting this flag would dismiss an insecure keyguard.
So is this a feature or a bug? What's the workaround?
Disabling keyguard via PowerManager class is an option, but it can't work like dismissal style. Can it?
Upvotes: 4
Views: 5056
Reputation: 3512
First: It's a bug.
Second, Is there a workaround? Yes.
Because I stumpled upon this issue and even google did not know this issue, I made a tremendous research on how to work around this. It's quite easy. The bug is presumably that the keyguard is registered two times android intern.
The trick is to start a pre running activity in forehand, listening to screen on broadcasts, dismissing the keyguard and start your real intented activity.
Code:
public class KeyGuardDismissActivity extends Activity {
private ScreenOnReceiver receiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LOG.d("Start keyguard dismisser!");
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
startActivity(new SomeOtherActivityIntent(getApplicationContext()));
finish();
return;
}
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
receiver = new ScreenOnReceiver();
registerReceiver(receiver, receiver.getFilter());
}
private void dismissingKeyguard() {
LOG.d("Dismissing keyguard!");
SomeOtherActivityIntent yourRealActivity = new SomeOtherActivityIntent(getApplicationContext(), this);
startActivity(yourRealActivity );
if (receiver != null) {
unregisterReceiver(receiver);
}
finish();
}
private class ScreenOnReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
LOG.d("Screen on, yay!");
dismissingKeyguard();
}
public IntentFilter getFilter() {
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_SCREEN_ON);
return filter;
}
}
}
In your real activity you have to add the dismiss flag, too!
Greetings.
Upvotes: 3