How to check the device has set password or not in android?

大城市里の小女人 提交于 2019-12-24 13:54:54

问题


In my application, I want to check whether the user has set the password in their android device or not? I tried using device admin apis m not able to get those information. Is there any other way?


回答1:


Device administrator doesn't allow you to check whether device has lock screen password (or pattern ...) directly.

However you can do it indirectly.

  1. Retrieve password quality level from device admin (original value)
  2. Set password quality to device admin to minimum level (i.e. PASSWORD_QUALITY_SOMETHING)
  3. Ask device admin whether is password quality sufficient (if true = user has password)
  4. Restore original password quality level (value from step 1)

DevicePolicyManager allows you to set/get required password quality level and check whether is password sufficient.

Your device admin will need to use limit-pasword policy:

<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
  <uses-policies>
    <limit-password />
  </uses-policies>
</device-admin>

And you should definetely read this Device Administrator Guide.



来源:https://stackoverflow.com/questions/16910698/how-to-check-the-device-has-set-password-or-not-in-android

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