4

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.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
thanhbinh84
  • 17,876
  • 6
  • 62
  • 69
  • 1
    Be a Vendor / System app. – Shark Jun 23 '17 at 12:22
  • 1
    You cann't without System Permissions, because next swipe to unlock (with pin), based on System, and on some other device, there willn't be seconds screen, but just PIN. – GensaGames Jun 23 '17 at 18:32
  • @GensaGames it means it is impossible with unrooted devices? – thanhbinh84 Jun 24 '17 at 01:08
  • 1
    After looking at how gravitybox does it, I've come to the conclusion that there is in fact no way to achieve this without root. Reference https://github.com/GravityBox/GravityBox/blob/marshmallow/src/com/ceco/marshmallow/gravitybox/ModLockscreen.java with settings key PREF_KEY_LOCKSCREEN_DIRECT_UNLOCK – F43nd1r Jun 24 '17 at 21:54

1 Answers1

2

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);
    }
};
danhnn.uit
  • 1,784
  • 1
  • 14
  • 7