Pages

Friday, February 1, 2013

Enable & Disable Key Lock In android Application

key Lock Enable and Disable in android application



Function for Disable Keylock

// object....


KeyguardManager keyguardManager;
KeyguardLock lock;

public void Disable_AutoLock() {   
 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
 keyguardManager = (KeyguardManager) getSystemService(Activity.KEYGUARD_SERVICE);
 lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);       
 lock.disableKeyguard();
}

Function for enable KeyLock


public void Enable_AutoLock()
{
   lock.reenableKeyguard();
}

Need to add permission in AndoridManifest.xml 
  

<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

   



No comments:

Post a Comment