PowerManager获取WackLock以及相关flag含义
2016-05-20 15:01
363 查看
文章转自:http://www.cnblogs.com/GnagWang/archive/2011/02/27/1966611.html
感谢博主总结!!!
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);通过
然后通过PowerManager的newWakeLock((int flags, String tag)来生成WakeLock实例。int
Flags指示要获取哪种WakeLock,不同的Lock对cpu 、屏幕、键盘灯有不同影响。
获取WakeLock实例后通过acquire()获取相应的锁,然后进行其他业务逻辑的操作,最后使用release()释放(释放是必须的)。
各种锁的类型对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.
另外WakeLock的设置是 Activiy 级别的,不是针对整个Application应用的。
可以在activity的onResume方法里面操作WakeLock, 在onPause方法里面释放。
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);通过
然后通过PowerManager的newWakeLock((int flags, String tag)来生成WakeLock实例。int
Flags指示要获取哪种WakeLock,不同的Lock对cpu 、屏幕、键盘灯有不同影响。
获取WakeLock实例后通过acquire()获取相应的锁,然后进行其他业务逻辑的操作,最后使用release()释放(释放是必须的)。
各种锁的类型对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.
另外WakeLock的设置是 Activiy 级别的,不是针对整个Application应用的。
可以在activity的onResume方法里面操作WakeLock, 在onPause方法里面释放。
感谢博主总结!!!
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方法里面释放。
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方法里面释放。
相关文章推荐
- org.apache.log4j.Logger详解
- mssql表值函数
- C#中CLR(公共语言运行时)与IL(中间代码)
- 快速幂或者矩阵快速幂
- css对图片圆角处理
- From Core Java Volume Ⅰ(1)
- js中===和==的区别
- POJ 3126 Prime Path
- 操作系统知识(6)--Shell初探
- input框的默认bug解决办法
- 高并发集中访问造成连接MYSQL报Cannot assign requested address错误
- NSString 和 NSMutableString类的常见用法
- RabbitMq、ActiveMq、ZeroMq、kafka
- x64 Tail Call Elimination
- iOS学习之—— UICollectionView导致的崩溃问题
- AndroidStudio入门----Eclipse快捷键配置
- 人手检测
- c++ primer plus 第13章习题
- live your life with passion
- 手机端网页自适应解决方案