Lock/unlock android phone programatically

Lock and unlock phone in android programmatically/ Lock phone using power manager/wave lock in android/Turn screen off in android/Display screen off in android

To turn screen on in android, use the code below



powermanager=  ((PowerManager)context.getSystemService(Context.POWER_SERVICE));
                 wakeLock=powermanager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP"tag");
            wakeLock.acquire();


To lock or to turn off display screen off, use the code below

if(wakeLock.isHeld())
            {
                  wakeLock.release();
            }

Also set permission in Android manifest file

<uses-permission android:name="android.permission.WAKE_LOCK"/>
Lock/unlock android phone programatically Lock/unlock android phone programatically Reviewed by Unknown on 12:10 AM Rating: 5

1 comment:

Theme images by enjoynz. Powered by Blogger.