<!-- @page { margin: 0.79in } P { margin-bottom: 0.08in } H1 { margin-bottom: 0.08in } H1.western { font-family: "Times New Roman", serif } H1.cjk { font-family: "DejaVu Sans" } H1.ctl { font-family: "Lohit Hindi" } TD P { margin-bottom: 0in } H2 { margin-bottom: 0.08in } H2.ctl { font-family: "Lohit Hindi" } PRE.cjk { font-family: "DejaVu Sans", monospace } TH P { margin-bottom: 0in } CODE.cjk { font-family: "DejaVu Sans", monospace } -->
public class
PowerManager
extends Object
java.lang.Object | |
↳ | android.os.PowerManager |
类概括
Class Overview
本类使你能控制设备能量状态。
This class gives you control of the power state of the device.
设备电池生命将会受到这个API的使用的重大影响。除非你真正需要他们不要获得WakeLocks,尽可能使用最小等级,并且确保一旦你能够就释放他。
Device battery life will be significantly affected by the use of this API. Do not acquire WakeLocks unless you really need them, use the minimum levels possible, and be sure to release it as soon as you can.
你可以通过调用Context.getSystemService()获得这个类的一个实例。
You can obtain an instance of this class by calling Context.getSystemService()
.
首先你要用到的API是newWakeLock()。这个方法将建立一个PowerManager.WakeLock对象。你能够这样使用方法通过这个对象来控制设备的能量状态。实践起来十分简单:
The primary API you'll use is newWakeLock()
. This will create a PowerManager.WakeLock
object. You can then use methods on this object to control the power state of the device. In practice it's quite simple:
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag"); wl.acquire(); ..screen will stay on during this section.. wl.release();
以下定义的标志,以及对系统能量的不同影响。有些标志是相互独立-你可能仅指定他们之一。
The 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 |
---|---|---|---|
| 开On* | 关Off | 关Off |
| 开On | 暗Dim | 关Off |
| 开On | 亮Bright | 关Off |
| 开On | 亮Bright | 亮Bright |
*如果你获得一个不完整的wakelock,则CPU会继续运行,不必顾及任何计时器甚至用户按下power键后。对于所有的其他的wakelock,CPU在运行,但用户可以直接用power键使设备休眠。
*If you hold a partial wakelock, the CPU will continue to run, irrespective of any timers and even after the user presses the power button. In all other wakelocks, the CPU will run, but the user can still put the device to sleep using the power button.
另外,你能加两个以上的标志,这些仅能影响屏幕的行为。这些标志当组合中有一个PARTIAL_WAKE_LOCK时将没有效果。
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 |
---|---|
|
正常的wake lock不会实际转到照明。反而,他们使照明保持自他打开时(例如,来自用户activity)。这个标志会强制屏幕和/或键盘立即打开,当这个wakelock已获取时。一个典型用法是将哪些重要的通知立即让用户看到。 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. |
|
如果这个标志被设置,用户activity计时器当WakeLock被释放时会重新设定,因为照明保持一点长。这个可以用于降低闪烁如果你是在wake lock状态下循环。 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. |
Summary
Nested Classes | |||
---|---|---|---|
class | PowerManager.WakeLock | 类让你说你需要有这个设备。 Class lets you say that you need to have the device on. |
Constants | |||
---|---|---|---|
int | ACQUIRE_CAUSES_WAKEUP | 正常的wake lock不会实际的唤醒设备,他们自他准备好则保持着。 Normally wake locks don't actually wake the device, they just cause it to remain on once it's already on. | |
int | FULL_WAKE_LOCK | Wake lock 以确保屏幕和键盘全部点亮。 Wake lock that ensures that the screen and keyboard are on at full brightness. | |
int | ON_AFTER_RELEASE | 当这个wake lock已释放时,拨开了用户界面的计时器所以屏幕停留稍微长。 When this wake lock is released, poke the user activity timer so the screen stays on for a little longer. | |
int | PARTIAL_WAKE_LOCK | Wake lock以确保CPU运行。 Wake lock that ensures that the CPU is running. | |
int | SCREEN_BRIGHT_WAKE_LOCK | Wake lock以确保屏幕全亮;键盘背光允许关闭。 Wake lock that ensures that the screen is on at full brightness; the keyboard backlight will be allowed to go off. | |
int | SCREEN_DIM_WAKE_LOCK | Wake lock以确保屏幕打开(但可以是暗淡的);键盘背光将允许关闭。 Wake lock that ensures that the screen is on (but may be dimmed); the keyboard backlight will be allowed to go off. |
Public Methods | ||
---|---|---|
void | goToSleep(long time) 强制设备进入休眠。 Force the device to go to sleep. | |
boolean | IsScreenOn() 返回屏幕是否当前亮着。 Returns whether the screen is currently on. | |
PowerManager.WakeLock | newWakeLock(int flags, String tag) 得到一个Wake lock在这个标志参数的级别。 Get a wake lock at the level of the flags parameter. | |
void | reboot(String reason) 重启设备 Reboot the device. | |
void | userActivity(long when, boolean noChangeLights) 用户界面发生。 User activity happened. |