0

I am trying to build an app in android which on launch checks whether the device is secure with any kind of pattern,or pin i found this method of keyguardManager isDeviceSecure() it says it return true if the device is secured with a PIN, pattern or password.

Deepanshu Namdeo
  • 159
  • 1
  • 12

1 Answers1

0

You can check this with the DevicePolicyManager:

DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);

int passwordQuality = devicePolicyManager.getPasswordQuality(//componentName of device admin here);

if (passwordQuality == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) {
    // Any password/pincode/swipe is set up.
}

if (devicePolicyManager.isActivePasswordSufficient()) {
    // With this you can check if the device password is sufficient (for example if password quality changes).
}

You may need admin application rights to do this tough (unsure). Read more here : https://developer.android.com/reference/android/app/admin/DevicePolicyManager.html

EDIT:

You could also extend DeviceAdminReceiver in order to catch the Intent when a user changes his pin or password.

public class MyDeviceAdminReceiver extends DeviceAdminReceiver {


@Override
    public void onPasswordChanged(Context context, Intent intent) {
        // Display your dialog here if user set any type of password.
    }

}
Fatmajk
  • 1,770
  • 1
  • 13
  • 22
  • What is componentName of admin? – Deepanshu Namdeo Apr 23 '18 at 13:35
  • I think it would be really useful for you to read this: https://developer.android.com/guide/topics/admin/device-admin.html. It will answer some of your questions for sure. I've edited my answer to be even more clear. – Fatmajk Apr 23 '18 at 13:42
  • i think you have not understood my question. – Deepanshu Namdeo Apr 24 '18 at 06:51
  • What i am saying is like i want my app to check whether the user set any type of password or pin or pattern.if user did have this enable the application should present an alertDialog saying device have lock enable. – Deepanshu Namdeo Apr 24 '18 at 06:54
  • Well I gave you the answer? You can do it with the DevicePolicyManager on application launch. Otherwise you can extend the DeviceAdminReceiver in order to catch some security/password Intents. I've edited my answer above. Otherwise I don't understand what you want to achieve. – Fatmajk Apr 24 '18 at 07:31