Android屏幕解锁和点亮
2013-01-09 14:27
411 查看
有些场景需要程序自动点亮屏幕,解开屏幕锁,以方便用户即时操作,下面用代码来实现这一功能:
需要在AndroidManifest.xml添加权限:
flags参数说明:
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.
2、保持屏幕唤醒
use the window flag FLAG_KEEP_SCREEN_ON把下面的代码加入到程序onCreate方法中
1.//得到键盘锁管理器对象 2.KeyguardManager km= (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); 3.//参数是LogCat里用的Tag 4.KeyguardLock kl = km.newKeyguardLock("unLock"); 5.//解锁 6.kl.disableKeyguard(); 7. 8.//获取电源管理器对象 9.PowerManager pm=(PowerManager) getSystemService(Context.POWER_SERVICE); 10.//获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是LogCat里用的Tag 11.PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "bright"); 12.//点亮屏幕 13.wl.acquire(); 14.//释放 15.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.
2、保持屏幕唤醒
use the window flag FLAG_KEEP_SCREEN_ON把下面的代码加入到程序onCreate方法中
@Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); // Set keep screen on getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); }
相关文章推荐
- Android屏幕点亮(常亮)及屏幕解锁和锁定 全屏显示
- Android 手机锁屏下点亮屏幕并解锁(没有锁屏密码的情况下)
- Android点亮屏幕和解锁完整示例
- Android点亮屏幕和解锁完整示例
- android 解锁 点亮屏幕
- Android程序主动点亮&解锁屏幕的实现
- Android设备屏幕锁定/解锁/屏幕点亮监听
- Android设备屏幕锁定/解锁/屏幕点亮监听
- android 点亮手机屏幕与屏幕解锁方法
- Android屏幕点亮(常亮)及屏幕解锁和锁定
- Android点亮屏幕并解锁
- android 唤醒屏幕,解锁以及部分机型点亮屏幕却没有解锁的问题
- android 点亮屏幕与解锁
- Android程序主动点亮&解锁屏幕的实现
- android 电源管理,屏幕锁 ,小米2s点亮屏幕,解锁
- Android屏幕点亮(常亮)及屏幕解锁和锁定
- Android设备屏幕锁定/解锁/屏幕点亮监听
- Android点亮屏幕或屏幕解锁和锁定以及其他相关权限实现代码
- Android屏幕解锁和点亮