简体   繁体   中英

Use setRequiredPasswordComplexity(passwordComplexity : Int) in API less than 31

I want to set password policy on screen lock and now I use setPasswordQuality(ComponentName admin, int quality) in DevicePolicyManager but this method is deprecated on API 31 and they add new method(setRequiredPasswordComplexity(passwordComplexity: Int)). I can use this method in API < 31? If I can,how should I use it? https://developer.android.com/reference/android/app/admin/DevicePolicyManager#setRequiredPasswordComplexity(int)

As the documentation already states the method was added in API 31 and since there is no backward compatibility library for this so this functionality can only be used on devices with api 31 or above

I think your problem might solve here . You can check the build version by

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S){
                        // Do something for version 31 and above versions
} else{
                        // do something for phones running an SDK before 31
                    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM