IT. Expert System.

Android Reference

PowerManager


android.os

Class PowerManager



  • public final class PowerManager
    extends Object
    This class gives you control of the power state of the device.

    Device battery life will be significantly affected by the use of this API. Do not acquire PowerManager.WakeLocks unless you really need them, use the minimum levels possible, and be sure to release them as soon as possible.

    You can obtain an instance of this class by calling Context.getSystemService().

    The primary API you'll use is newWakeLock(). This will create a PowerManager.WakeLock object. You can then use methods on the wake lock object to control the power state of the device.

    In practice it's quite simple:

    The following wake lock levels are defined, with varying effects on system power. These levels 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

    *If you hold a partial wake lock, the CPU will continue to run, regardless of any display timeouts or the state of the screen and even after the user presses the power button. In all other wake locks, the CPU will run, but the user can still put the device to sleep using the power button.

    In addition, you can add two more flags, which affect behavior of the screen only. These flags have no effect when combined with a PARTIAL_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 would be for notifications 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 cycling between wake lock conditions.

    Any application using a WakeLock must request the android.permission.WAKE_LOCK permission in an <uses-permission> element of the application's manifest.

    • Field Detail

      • PARTIAL_WAKE_LOCK

        public static final int PARTIAL_WAKE_LOCK
        Wake lock level: Ensures that the CPU is running; the screen and keyboard backlight will be allowed to go off.

        If the user presses the power button, then the screen will be turned off but the CPU will be kept on until all partial wake locks have been released.

        See Also:
        Constant Field Values
      • SCREEN_DIM_WAKE_LOCK

        @Deprecated
        public static final int SCREEN_DIM_WAKE_LOCK
        Deprecated. Most applications should use WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON instead of this type of wake lock, as it will be correctly managed by the platform as the user moves between applications and doesn't require a special permission.
        Wake lock level: Ensures that the screen is on (but may be dimmed); the keyboard backlight will be allowed to go off.

        If the user presses the power button, then the SCREEN_DIM_WAKE_LOCK will be implicitly released by the system, causing both the screen and the CPU to be turned off. Contrast with PARTIAL_WAKE_LOCK.

        See Also:
        Constant Field Values
      • SCREEN_BRIGHT_WAKE_LOCK

        @Deprecated
        public static final int SCREEN_BRIGHT_WAKE_LOCK
        Deprecated. Most applications should use WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON instead of this type of wake lock, as it will be correctly managed by the platform as the user moves between applications and doesn't require a special permission.
        Wake lock level: Ensures that the screen is on at full brightness; the keyboard backlight will be allowed to go off.

        If the user presses the power button, then the SCREEN_BRIGHT_WAKE_LOCK will be implicitly released by the system, causing both the screen and the CPU to be turned off. Contrast with PARTIAL_WAKE_LOCK.

        See Also:
        Constant Field Values
      • FULL_WAKE_LOCK

        @Deprecated
        public static final int FULL_WAKE_LOCK
        Deprecated. Most applications should use WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON instead of this type of wake lock, as it will be correctly managed by the platform as the user moves between applications and doesn't require a special permission.
        Wake lock level: Ensures that the screen and keyboard backlight are on at full brightness.

        If the user presses the power button, then the FULL_WAKE_LOCK will be implicitly released by the system, causing both the screen and the CPU to be turned off. Contrast with PARTIAL_WAKE_LOCK.

        See Also:
        Constant Field Values
      • PROXIMITY_SCREEN_OFF_WAKE_LOCK

        public static final int PROXIMITY_SCREEN_OFF_WAKE_LOCK
        Wake lock level: Turns the screen off when the proximity sensor activates.

        If the proximity sensor detects that an object is nearby, the screen turns off immediately. Shortly after the object moves away, the screen turns on again.

        A proximity wake lock does not prevent the device from falling asleep unlike FULL_WAKE_LOCK, SCREEN_BRIGHT_WAKE_LOCK and SCREEN_DIM_WAKE_LOCK. If there is no user activity and no other wake locks are held, then the device will fall asleep (and lock) as usual. However, the device will not fall asleep while the screen has been turned off by the proximity sensor because it effectively counts as ongoing user activity.

        Since not all devices have proximity sensors, use isWakeLockLevelSupported(int) to determine whether this wake lock level is supported.

        See Also:
        Constant Field Values
      • WAKE_LOCK_LEVEL_MASK

        public static final int WAKE_LOCK_LEVEL_MASK
        Mask for the wake lock level component of a combined wake lock level and flags integer.
        See Also:
        Constant Field Values
      • ACQUIRE_CAUSES_WAKEUP

        public static final int ACQUIRE_CAUSES_WAKEUP
        Wake lock flag: Turn the screen on when the wake lock is acquired.

        Normally wake locks don't actually wake the device, they just cause the screen to remain on once it's already on. Think of the video player application as the normal behavior. Notifications that pop up and want the device to be on are the exception; use this flag to be like them.

        Cannot be used with PARTIAL_WAKE_LOCK.

        See Also:
        Constant Field Values
      • ON_AFTER_RELEASE

        public static final int ON_AFTER_RELEASE
        Wake lock flag: When this wake lock is released, poke the user activity timer so the screen stays on for a little longer.

        Will not turn the screen on if it is not already on. See ACQUIRE_CAUSES_WAKEUP if you want that.

        Cannot be used with PARTIAL_WAKE_LOCK.

        See Also:
        Constant Field Values
      • WAIT_FOR_PROXIMITY_NEGATIVE

        public static final int WAIT_FOR_PROXIMITY_NEGATIVE
        Flag for release(int) to defer releasing a #WAKE_BIT_PROXIMITY_SCREEN_OFF wake lock until the proximity sensor returns a negative value.
        See Also:
        Constant Field Values
      • BRIGHTNESS_ON

        public static final int BRIGHTNESS_ON
        Brightness value for fully on.
        See Also:
        Constant Field Values
      • BRIGHTNESS_OFF

        public static final int BRIGHTNESS_OFF
        Brightness value for fully off.
        See Also:
        Constant Field Values
      • USER_ACTIVITY_EVENT_OTHER

        public static final int USER_ACTIVITY_EVENT_OTHER
        User activity event type: Unspecified event type.
        See Also:
        Constant Field Values
      • USER_ACTIVITY_EVENT_BUTTON

        public static final int USER_ACTIVITY_EVENT_BUTTON
        User activity event type: Button or key pressed or released.
        See Also:
        Constant Field Values
      • USER_ACTIVITY_EVENT_TOUCH

        public static final int USER_ACTIVITY_EVENT_TOUCH
        User activity event type: Touch down, move or up.
        See Also:
        Constant Field Values
      • USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS

        public static final int USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS
        User activity flag: Do not restart the user activity timeout or brighten the display in response to user activity if it is already dimmed.
        See Also:
        Constant Field Values
      • GO_TO_SLEEP_REASON_USER

        public static final int GO_TO_SLEEP_REASON_USER
        Go to sleep reason code: Going to sleep due by user request.
        See Also:
        Constant Field Values
      • GO_TO_SLEEP_REASON_DEVICE_ADMIN

        public static final int GO_TO_SLEEP_REASON_DEVICE_ADMIN
        Go to sleep reason code: Going to sleep due by request of the device administration policy.
        See Also:
        Constant Field Values
      • GO_TO_SLEEP_REASON_TIMEOUT

        public static final int GO_TO_SLEEP_REASON_TIMEOUT
        Go to sleep reason code: Going to sleep due to a screen timeout.
        See Also:
        Constant Field Values
    • Constructor Detail

      • PowerManager

        public PowerManager(Context context,
                    IPowerManager service,
                    Handler handler)
    • Method Detail

      • getMinimumScreenBrightnessSetting

        public int getMinimumScreenBrightnessSetting()
        Gets the minimum supported screen brightness setting. The screen may be allowed to become dimmer than this value but this is the minimum value that can be set by the user.
      • getMaximumScreenBrightnessSetting

        public int getMaximumScreenBrightnessSetting()
        Gets the maximum supported screen brightness setting. The screen may be allowed to become dimmer than this value but this is the maximum value that can be set by the user.
      • getDefaultScreenBrightnessSetting

        public int getDefaultScreenBrightnessSetting()
        Gets the default screen brightness setting.
      • useScreenAutoBrightnessAdjustmentFeature

        public static boolean useScreenAutoBrightnessAdjustmentFeature()
        Returns true if the screen auto-brightness adjustment setting should be available in the UI. This setting is experimental and disabled by default.
      • useTwilightAdjustmentFeature

        public static boolean useTwilightAdjustmentFeature()
        Returns true if the twilight service should be used to adjust screen brightness policy. This setting is experimental and disabled by default.
      • validateWakeLockParameters

        public static void validateWakeLockParameters(int levelAndFlags,
                                      String tag)
      • userActivity

        public void userActivity(long when,
                        boolean noChangeLights)
        Notifies the power manager that user activity happened.

        Resets the auto-off timer and brightens the screen if the device is not asleep. This is what happens normally when a key or the touch screen is pressed or when some other user activity occurs. This method does not wake up the device if it has been put to sleep.

        Requires the android.Manifest.permission#DEVICE_POWER permission.

        Parameters:
        when - The time of the user activity, in the SystemClock.uptimeMillis() time base. This timestamp is used to correctly order the user activity request with other power management functions. It should be set to the timestamp of the input event that caused the user activity.
        noChangeLights - If true, does not cause the keyboard backlight to turn on because of this event. This is set when the power key is pressed. We want the device to stay on while the button is down, but we're about to turn off the screen so we don't want the keyboard backlight to turn on again. Otherwise the lights flash on and then off and it looks weird.
        See Also:
        wakeUp(long), goToSleep(long)
      • goToSleep

        public void goToSleep(long time)
        Forces the device to go to sleep.

        Overrides all the wake locks that are held. This is what happens when the power key is pressed to turn off the screen.

        Requires the android.Manifest.permission#DEVICE_POWER permission.

        Parameters:
        time - The time when the request to go to sleep was issued, in the SystemClock.uptimeMillis() time base. This timestamp is used to correctly order the go to sleep request with other power management functions. It should be set to the timestamp of the input event that caused the request to go to sleep.
        See Also:
        userActivity(long, boolean), wakeUp(long)
      • wakeUp

        public void wakeUp(long time)
        Forces the device to wake up from sleep.

        If the device is currently asleep, wakes it up, otherwise does nothing. This is what happens when the power key is pressed to turn on the screen.

        Requires the android.Manifest.permission#DEVICE_POWER permission.

        Parameters:
        time - The time when the request to wake up was issued, in the SystemClock.uptimeMillis() time base. This timestamp is used to correctly order the wake up request with other power management functions. It should be set to the timestamp of the input event that caused the request to wake up.
        See Also:
        userActivity(long, boolean), goToSleep(long)
      • nap

        public void nap(long time)
        Forces the device to start napping.

        If the device is currently awake, starts dreaming, otherwise does nothing. When the dream ends or if the dream cannot be started, the device will either wake up or go to sleep depending on whether there has been recent user activity.

        Requires the android.Manifest.permission#DEVICE_POWER permission.

        Parameters:
        time - The time when the request to nap was issued, in the SystemClock.uptimeMillis() time base. This timestamp is used to correctly order the nap request with other power management functions. It should be set to the timestamp of the input event that caused the request to nap.
        See Also:
        wakeUp(long), goToSleep(long)
      • setBacklightBrightness

        public void setBacklightBrightness(int brightness)
        Sets the brightness of the backlights (screen, keyboard, button).

        Requires the android.Manifest.permission#DEVICE_POWER permission.

        Parameters:
        brightness - The brightness value from 0 to 255.
      • isWakeLockLevelSupported

        public boolean isWakeLockLevelSupported(int level)
        Returns true if the specified wake lock level is supported.
        Parameters:
        level - The wake lock level to check.
        Returns:
        True if the specified wake lock level is supported.
      • isScreenOn

        public boolean isScreenOn()
        Returns whether the screen is currently on.

        Only indicates whether the screen is on. The screen could be either bright or dim.

        Returns:
        whether the screen is on (bright or dim).
      • reboot

        public void reboot(String reason)
        Reboot the device. Will not return if the reboot is successful.

        Requires the android.Manifest.permission#REBOOT permission.

        Parameters:
        reason - code to pass to the kernel (e.g., "recovery") to request special boot modes, or null.


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 597 / 158726648. Delta: 0.04705 с