Android屏幕解锁和点亮
来源:互联网 发布:域名怎么抢注 编辑:程序博客网 时间:2024/04/30 17:20
有些场景需要程序自动点亮屏幕,解开屏幕锁,以方便用户即时操作,下面用代码来实现这一功能:
- //得到键盘锁管理器对象
- KeyguardManager km= (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
- //参数是LogCat里用的Tag
- KeyguardLock kl = km.newKeyguardLock("unLock");
- //解锁
- kl.disableKeyguard();
- //获取电源管理器对象
- PowerManager pm=(PowerManager) getSystemService(Context.POWER_SERVICE);
- //获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是LogCat里用的Tag
- PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK,"bright");
- //点亮屏幕
- wl.acquire();
- //释放
- wl.release();
需要在AndroidManifest.xml添加权限:
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
flags参数说明:
- PARTIAL_WAKE_LOCK: Screen off, keyboard light off
- SCREEN_DIM_WAKE_LOCK: screen dim, keyboard light off
- SCREEN_BRIGHT_WAKE_LOCK: screen bright, keyboard light off
- FULL_WAKE_LOCK: screen bright, keyboard bright
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.
转载于:http://www.ziyouku.com/archives/android-unlock-the-screen-and-the-light.html
- Android屏幕解锁和点亮
- Android屏幕解锁和点亮
- Android屏幕解锁和点亮
- Android屏幕解锁和点亮
- Android屏幕解锁和点亮
- android 点亮屏幕和屏幕解锁
- android 解锁 点亮屏幕
- Android点亮解锁屏幕
- 屏幕解锁和点亮
- Android点亮屏幕和解锁完整示例
- Android监控屏幕解锁和点亮
- android解锁屏幕,点亮屏幕
- 点亮屏幕和屏幕解锁
- 点亮屏幕和屏幕解锁
- Android屏幕点亮(常亮)及屏幕解锁和锁定
- Android屏幕点亮(常亮)及屏幕解锁和锁定
- Android点亮屏幕或屏幕解锁和锁定
- Android屏幕点亮(常亮)及屏幕解锁和锁定
- TreeView 用法(有代码)
- 2011年总结
- c# sql like @参数
- MVC框架 IE浏览时IIS配置
- jquery筛选数组之grep、each、inArray、map的用法及遍历json对象
- Android屏幕解锁和点亮
- 将pthread库改名字了,差点系统就完蛋了
- 一个月的第一天和最后一天
- Android文本EditorText相关问题
- 再谈编译过程
- maven3学习笔记3--maven的坐标
- Android相机Camera相关问题
- Flare3D - 一些不足之处
- 扯,或者不扯,淡就在那里,不痛不痒。