How to bypass the "swipe to unlock" screen

I implement a custom “swipe to unlock” screen.

If “Screen lock” in the “Scroll” settings, my application is working correctly. On my screen, “swipe the unlock screen” → “User scroll” to unlock → he unlocks the phone and goes to the main screen, adding the following code to his activity:

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

The problem occurs when the "Screen Lock" in the "PIN" settings, the code above does not affect. I expect it to turn off the default swipe screen and go to the PIN code screen, so users don’t have to scroll twice to enter their PIN code.

UPDATE:

It seems that we cannot escape the default screen to unlock it, so I am trying to use a different approach using a fingerprint.

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

For now, I have to touch the sensor twice, first remove the lock screen and the second one for the default lock screen. The following application can turn off 2 lock screens with one touch, so I think it is possible.

If you have any suggestions, please let me know. Many thanks.

+4
source share
1 answer

No need to listen to the fingerprint, just register when the device is unlocked and release the 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);
    }
};
+2
source

Source: https://habr.com/ru/post/1679807/


All Articles