I'm really rather new to android dev and I am building an app and one of the features is to do something if getCurrentFailedPasswordAttempts() > 4, but it seems that no one has either ever had a problem figuring it out other than me or no one has ever tried.

My app calls lockNow() in my activity, I need to understand when getCurrentFailedAttempts() needs to be called, how, and in what order. I manage to get it to return 0 every single time, but it returns just as I get the lock screen.

   public void onPasswordFailed(Context context, Intent intent) {
        DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
        int numFailedAttempts = dpm.getCurrentFailedPasswordAttempts();
    if(numFailedAttempts  > 4){
        //do stuff

I've tried calling it in several oncreate functions and several onstart functions with no luck. It goes to the lock screen and then somehow it should say hey that was too many tries and then do the thing we want to do. Is there some function that is used specifically for working with returning from the lock screen? Should this check be done in a service? Should this be done in onResume instead?

Any and all helpful responses are appreciated and questions are more than welcome.

I think I spent maybe about 3 hours worth of research before jumping into a question. I don't need documentation quotes although they are always welcome. I've read the documentation many times, what I really need is some insight and maybe someone with some experience on the topic.

Related posts

Recent Viewed