Device Password in Android is existing or not
I am trying to know whether a screen lock password is already present or not, when my app has started.
case 1: If there is a s开发者_运维知识库creen lock password already... I would do the locking (locknow()) using device manager and ask the user to login again.
case 2: If there is no screen lock password.... i would ask user to set a password using devicepolicymanager class.
But I was unable to know, how to check whether a screen lock password is already present or not. is there any boolean returning method in device manager api ?...i was unable any of such
I was able to know whether active admins are present or not.... now,can someone tell me how to know whether a screen lock password is already present or not ...
Is it a secuirty thing that app developers are not allowed to find?
Is there a system level approach?
can device policy manager help me to get that info?
thanks in advance
KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
if( keyguardManager.isKeyguardSecure()) {
//it is password protected
} else {
//it is not password protected
}
The method isKeyguardSecure() is introduced in API Level 16
Look here How to reveal that screen is locked?. The matter was extensively discussed and resolved there
Try the following:
dpm.setPasswordMinimumLength(new ComponentName(<package>, <class>), 0);
Log.d("Log", "Reset done: " + dpm.resetPassword("", 0)); // i.e. clear password
Log.d("Log", "Sufficient: " + dpm.isActivePasswordSufficient());
Log.d("Log", "Reset done: " + dpm.resetPassword("0000", 0));
Log.d("Log", "Sufficient: " + dpm.isActivePasswordSufficient());
// of device admin receiver
dpm.setPasswordMinimumLength(new ComponentName(<package>, <class>), 1);
Log.d("Log", "Reset done: " + dpm.resetPassword("", 0));
Log.d("Log", "Sufficient: " + dpm.isActivePasswordSufficient());
Log.d("Log", "Reset done: " + dpm.resetPassword("0000", 0));
Log.d("Log", "Sufficient: " + dpm.isActivePasswordSufficient());
Conclusion:
use setPasswordMinimumLength(..., 1)
check if password is sufficient
if not set password with resetPassword()
call lockNow()
May be you have already found the solution. However I'm posting here this for the future reference.
You can use isActivePasswordSufficient() method in DevicePolicyManager to check the current status of the password as well as the availability.
Refer http://developer.android.com/reference/android/app/admin/DevicePolicyManager.html#isActivePasswordSufficient%28%29 for more details.
精彩评论