Thursday, 2 May 2013

Disable Auto lock in android

import android.app.Activity;
       import android.app.KeyguardManager;
       import android.app.KeyguardManager.KeyguardLock;
       import android.content.Context;
       import android.os.PowerManager;
       import android.view.WindowManager;

       public class AutoLock extends Activity
       {
              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();
              }
              public void Enable_AutoLock()
              {
                     lock.reenableKeyguard();
              }
       }

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

No comments:

Post a Comment