PowerManager和WakeLock的操作步骤
来源:互联网 发布:sql server 2008 sp4 编辑:程序博客网 时间:2024/05/22 21:00
- PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);通过
Context.getSystemService()
.方法获取PowerManager实例。 - 然后通过PowerManager的newWakeLock((int flags, String tag)来生成WakeLock实例。int Flags指示要获取哪种WakeLock,不同的Lock对cpu 、屏幕、键盘灯有不同影响。
- 获取WakeLock实例后通过acquire()获取相应的锁,然后进行其他业务逻辑的操作,最后使用release()释放(释放是必须的)。
关于int flags
各种锁的类型对CPU 、屏幕、键盘的影响:
PARTIAL_WAKE_LOCK:保持CPU 运转,屏幕和键盘灯有可能是关闭的。
SCREEN_DIM_WAKE_LOCK:保持CPU 运转,允许保持屏幕显示但有可能是灰的,允许关闭键盘灯
SCREEN_BRIGHT_WAKE_LOCK:保持CPU 运转,允许保持屏幕高亮显示,允许关闭键盘灯
FULL_WAKE_LOCK:保持CPU 运转,保持屏幕高亮显示,键盘灯也保持亮度
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:f 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.
权限获取
要进行电源的操作需要在AndroidManifest.xml中声明该应用有设置电源管理的权限。
<uses-permission android:name="android.permission.WAKE_LOCK" />你可能还需要<uses-permission android:name="android.permission.DEVICE_POWER" />
另外WakeLock的设置是 Activiy 级别的,不是针对整个Application应用的。
可以在activity的onResume方法里面操作WakeLock, 在onPause方法里面释放。
原文地址:http://www.cnblogs.com/GnagWang/archive/2011/02/27/1966611.html
- PowerManager和WakeLock的操作步骤
- PowerManager和WakeLock的操作步骤
- PowerManager和WakeLock的操作步骤
- PowerManager和WakeLock的操作步骤
- PowerManager和WakeLock的操作步骤
- PowerManager和WakeLock的操作步骤
- PowerManager和WakeLock的操作步骤
- PowerManager和WakeLock的操作步骤
- PowerManager和WakeLock的操作步骤
- PowerManager和WakeLock的操作步骤
- PowerManager WakeLock的操作步骤
- PowerManager 和WakeLock的操作
- android的PowerManager和PowerManager.WakeLock
- android的PowerManager和PowerManager.WakeLock
- android的PowerManager和PowerManager.WakeLock
- android的PowerManager和PowerManager.WakeLock
- android的PowerManager和PowerManager.WakeLock
- android的PowerManager和PowerManager.WakeLock
- 【错误记录】二维数组初始化,以二级指针传递函数参数
- Jimmy的文档:Glusterfs的rpc模块实现(第二部分)
- 开始毕业设计之旅
- SqlBulkCopy块拷贝数据时,不履行触发器和束缚 解决办法
- 函数#号图
- PowerManager和WakeLock的操作步骤
- apache 配置域名转向其它域名转到www域名
- 代码大全2(读书笔记16)
- JS验证URL
- sql中用CTE实现增加row_number()列
- Linux图形界面中客户端、服务器、窗口管理器之间的关系
- 深刻理解Python中的元类(metaclass)
- 快速排序
- 错误;找不到主类 Version3:TOSWT