Android Wakelock use method code instance _android

Source: Internet
Author: User
Android provides a class named Wakelock in Android.os.PowerManager.WakeLock, from the name of Wakelock is the meaning of wake-up lock, it can control the screen backlight switch, so in the power management class.
The Wakelock instantiation method is simpler because it is the remote service of the system, constructed by the following code
Copy Code code as follows:

PowerManager pm = (powermanager) getsystemservice (Context.power_service);
Powermanager.wakelock wl = Pm.newwakelock (Powermanager.screen_dim_wake_lock, "Android123"); The last parameter is the instance name and can be replaced with another one.
Wl.acquire (); Wake up and light up the screen
This period the screen will be lit
Wl.release (); Restore Screen to Darkness

Of course Android considering security does not mean that developers have permission, you can control the screen backlight or nothing, only through the acquire lit backlight to use release to turn off the backlight, if the direct call to the release method to close the screen will produce an exception.
Starting with the Android 2.1 API LEVEL7, you can use the public boolean Isscreenon () method to determine if the screen is lit and the code is
Copy Code code as follows:

PowerManager pm = (powermanager) getsystemservice (Context.power_service);
Boolean Isscreenon = Pm.isscreenon ();

For Android 2.2 API Level 8 added a reboot (), you can restart the phone into recovery mode, and you need to apply permissions to achieve, but the Android network does not guarantee that the method on all the firmware is effective, Some vendors have not developed this restart method considering security.
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.