Android wake, Unlock screen code instance _android

Source: Internet
Author: User

Unlock, wake up screen for Keyguardmanager,keyguardlock,powermanager,powermanager.wakelock

Required Permissions:

Copy Code code as follows:

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

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

Copy Code code as follows:

Lock screen, wake related
Private Keyguardmanager km;
Private Keyguardlock KL;
Private PowerManager pm;
Private Powermanager.wakelock WL;



private void Wakeandunlock (Boolean b)
{
if (b)
{
Get Power Manager Object
Pm= (PowerManager) Getsystemservice (Context.power_service);

Gets the Powermanager.wakelock object, and the following argument | Indicates that two values are passed in at the same time, and the last is the tag for debugging
WL = Pm.newwakelock (Powermanager.acquire_causes_wakeup | Powermanager.screen_bright_wake_lock, "BRIGHT");

Light up the screen
Wl.acquire ();

Get keyboard Lock Manager Object
Km= (Keyguardmanager) Getsystemservice (Context.keyguard_service);
KL = Km.newkeyguardlock ("UnLock");

Unlock
Kl.disablekeyguard ();
}
Else
{
Lock screen
Kl.reenablekeyguard ();

Release Wakelock, turn off the lights.
Wl.release ();
}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.