1

I want to Implement Screen lock in my app like, how Most of the payment gateway based apps do, I have tried using KeyGuardManager , which work after Lollipop only, the problem is my app also supports KitKat, that's why I need help

This is what I have Tried

KeyguardManager km = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
        if(km.isKeyguardSecure()) {

        Intent i = km.createConfirmDeviceCredentialIntent("Authentication required", "password");
        startActivityForResult(i, CODE_AUTHENTICATION_VERIFICATION);
    }
    else
        Toast.makeText(this, "No any security setup done by user(pattern or password or pin or fingerprint", Toast.LENGTH_SHORT).show();

1 Answers1

0

Look into Device Administration

You can set the maximum period of user inactivity that can occur before the device locks. For example:

DevicePolicyManager mDPM;
ComponentName mDeviceAdminSample;
...
long timeMs = 1000L*Long.parseLong(mTimeout.getText().toString());
mDPM.setMaximumTimeToLock(mDeviceAdminSample, timeMs);

You can also programmatically tell the device to lock immediately:

DevicePolicyManager mDPM;
mDPM.lockNow();

EDIT:

Don't forget to request the permission The docs state

The calling device admin must have requested USES_POLICY_FORCE_LOCK to be able to call this method; if it has not, a security exception will be thrown.

check this thread here

Rainmaker
  • 10,294
  • 9
  • 54
  • 89