android电源管理小总结

来源:互联网 发布:董云飞老师网络公开课 编辑:程序博客网 时间:2024/04/25 19:34

电源管理-官方提供示例以及文档说明

public final class

PowerManager

extends Object
java.lang.Object   ↳android.os.PowerManager

Class Overview


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:

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();


Flag ValueCPUScreenKeyboardPARTIAL_WAKE_LOCKOn*OffOffSCREEN_DIM_WAKE_LOCKOnDimOffSCREEN_BRIGHT_WAKE_LOCKOnBrightOffFULL_WAKE_LOCKOnBrightBright

更多细节官方链接 http://developer.android.com/reference/android/os/PowerManager.html

自己开发应用注意AndroidManifest.xml配置权限,不然会报错

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