Android screen always bright background always bright

Source: Internet
Author: User

Topic:

When the android program is running, the background light remains awake, that is, no black screen.

First run the Code:

Note that you need to add permissions

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

/***** @ Author zhujianbin **/public class utils {Private Static wakelock Wl;/*** keep the screen awake (that is, the background light is not off) * @ Param on whether to wake up */public static void keepscreenon (context, Boolean on) {If (on) {powermanager PM = (powermanager) context. getsystemservice (context. power_service); WL = PM. newwakelock (powermanager. screen_bright_wake_lock | powermanager. on_after_release, "= keepscreenon ="); WL. acquire ();} else {WL. release (); WL = NULL ;}}}


Explanation:

Classes used

Powermanager

These two parameters are used: powermanager. screen_bright_wake_lock | powermanager. on_after_release

Below is the official Android API
Explanation:

He following flags are defined, with varying effects on system power.These flags are mutually exclusive-you may only specify one of them.

Flag Value CPU Screen Keyboard
PARTIAL_WAKE_LOCK On * Off Off
SCREEN_DIM_WAKE_LOCK On Dim Off
SCREEN_BRIGHT_WAKE_LOCK On Bright Off
FULL_WAKE_LOCK On Bright Bright

It is generally necessary to keep the background normally when the program is running.

Screen_bright_wake_lock,

Screen_bright_wake_lock CPU: Wake up screen backlight: Wake up keyboard light: Off

The second parameter:

In addition, you can add two more flags, which affect behavior of the screen only.These flags have no effect when combined withPARTIAL_WAKE_LOCK.

Flag Value Description
ACQUIRE_CAUSES_WAKEUP Normal wake locks don't actually turn on the illumination. instead, they cause the illumination to remain on once it turns on (e.g. from user activity ). this flag will force the screen and/or keyboard to turn on immediately, when the wakelock is acquired.
A typical use wocould be for communications which are important for the user to see immediately.
ON_AFTER_RELEASE If this flag is set, the user activity timer will be reset when the wakelock is released, causing the illumination to remain on a bit longer. this can be used to reduce flicker if you are using ing between wake lock conditions.

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.