How to bypass 'swipe to unlock' screen

懵懂的女人 提交于 2019-12-10 16:10:06

问题


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.

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


回答1:


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


来源:https://stackoverflow.com/questions/44675989/how-to-bypass-swipe-to-unlock-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!