I am working on an application that will replace the default lock screen (swipe to unlock) for android devices. I have successfully done this by disabling the keyguard manager and showing my activity using the broadcast receiver for screen OFF and screen ON intent. Now, the problem is when I set the default screen lock again for any reason then my application would not disable the keyguard unless I force close it and launch it again.
      km = (KeyguardManager) getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE);
      if( km.inKeyguardRestrictedInputMode()) {
       //it is locked
          km = (KeyguardManager) getApplicationContext().getSystemService(KEYGUARD_SERVICE);
      kl=km.newKeyguardLock("com.example.helloworld.MainActivity");
      kl.disableKeyguard();
      } else {
          Intent i = getIntent();
          i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          getApplicationContext().startActivity(i);
      }
 
     
     
    