Android:powermanager Class Power Management

Source: Internet
Author: User

The PowerManager class is used to manage the power state of the device, the Powermanager.wakelock class is used to keep the device solid, and the power is controlled by various lock locks in Android, and it is important to note that the lock and unlock must appear in pairs.

Use the activity's life cycle to invoke keep the screen solid and free the screen-solid action.

    /**     * < function description > Keep the screen solid      *      * @return void [return type description] *    /private void Keepscreenwake () {        // Get Wakelock Lock, keep the screen solid        Mpowermanager = (powermanager) getsystemservice (context.power_service);        Mpowermanager.wakeup (Systemclock.uptimemillis ());        Mwakelock = Mpowermanager.newwakelock (Powermanager.full_wake_lock, this                . GetClass (). Getcanonicalname ());        Mwakelock.acquire ();    }

Accordingly, you need to release the on-screen operation in the activity's ondestory ().

    /**     * < function description > Release wakelock     *      * @return void [return type description]     *    /private void Releasewakelock () {        if (Mwakelock! = null && Mwakelock.isheld ()) {            mwakelock.release ();            Mwakelock = null;        }    }

For instructions on the various flags, these flags primarily affect the CPU, screen, and keyboard:

Partial_wake_lock: Keep the CPU running, the screen and keyboard lights may be off;

Screen_dim_wake_lock: Keep the CPU running, run keep the screen display but may be gray, run off the keyboard light;

Screen_bright_wake_lock: Keep the CPU running, run to keep the screen highlighted, run off the keyboard lights;

Full_wake_lock: Keep the CPU running, keep the screen highlighted, and the keyboard lights remain highlighted;

For the above power management settings, you need to obtain the relevant permissions of the system:

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

Android:powermanager Class Power Management

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.