thanhbinh84
thanhbinh84

Reputation: 18454

How to bypass 'swipe to unlock' screen

I am implementing a custom 'swipe to unlock' screen.

If the 'Screen lock' in settings is 'Swipe', my app work properly. In my custom 'swipe to unlock' screen -> User swipe to unlock -> it unlocks phone and go to home screen directly by adding the code below in my activity:

activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);

The problem arises when the 'Screen lock' in settings is 'PIN', the code above does not affect. What I expect is it will bypass the default 'swipe to unlock' screen and go to 'PIN input' screen, so users don't have to swipe twice to enter their PIN.

UPDATE:

It seems that we cannot avoid the default 'swipe to unlock' screen, so I try with another approach that using finger print.

@Override public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) { mCallback.onAuthenticated(); }

Currently, I have to touch to the sensor twice, first to dismiss my lock screen and second for the default lock screen. The next app can dismiss 2 lock screen with only one touch, so I think it is possible to do so.

Upvotes: 4

Views: 1735

Answers (1)

danhnn.uit
danhnn.uit

Reputation: 1794

Don’t need to listen to finger print, just register when device is unlocked and dismiss your lock screen:

void registerUnlockReceiver() {
    IntentFilter i = new IntentFilter(Intent.ACTION_USER_PRESENT);
    registerReceiver(mUserUnlockedReceiver , i);
}

BroadcastReceiver mUserUnlockedReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        unlockAndExit(false);
    }
};

Upvotes: 2

Related Questions