生活随笔
收集整理的這篇文章主要介紹了
android锁屏唤醒并解锁屏幕
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1、這個方法是實現(xiàn)鎖屏狀態(tài)下喚醒手機,亮屏并解鎖屏幕:
[java]?view plain
?copy public?static?void?wakeUpAndUnlock(Context?context){?? ???? ??KeyguardManager?km=?(KeyguardManager)?context.getSystemService(Context.KEYGUARD_SERVICE);?? ??KeyguardManager.KeyguardLock?kl?=?km.newKeyguardLock("unLock");?? ???? ??kl.disableKeyguard();?? ???? ??PowerManager?pm=(PowerManager)?context.getSystemService(Context.POWER_SERVICE);?? ???? ??PowerManager.WakeLock?wl?=?pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP?|?PowerManager.SCREEN_DIM_WAKE_LOCK,"bright");?? ???? ??wl.acquire();?? ???? ??wl.release();?? }??
加入權(quán)限:
[java]?view plain
?copy <uses-permission?android:name="android.permission.WAKE_LOCK"/>?? <uses-permission?android:name="android.permission.DISABLE_KEYGUARD"/>??
2、這個收集的:
[java]?view plain
?copy ?? ?private?KeyguardManager??km;?? ?private?KeyguardLock?kl;?? ?private?PowerManager?pm;?? ?private?PowerManager.WakeLock?wl;?? ??? ?private?void?wakeAndUnlock(boolean?b)?? ?{?? ???if(b)?? ???{?? ??????? ?????pm=(PowerManager)?getSystemService(Context.POWER_SERVICE);?? ??????? ?????wl?=?pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP?|?PowerManager.SCREEN_BRIGHT_WAKE_LOCK,?"bright");?? ??????? ?????wl.acquire();?? ??????? ?????km=?(KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);?? ?????kl?=?km.newKeyguardLock("unLock");?? ??????? ?????kl.disableKeyguard();?? ???}?? ???else?? ???{?? ??????? ?????kl.reenableKeyguard();?? ??????? ?????wl.release();?? ???}?? ?}??
說明:
getSystemService取不到就獲取上下文對象getActivity().getSystemService()。
原文地址: http://blog.csdn.net/bsmmaoshenbo/article/details/51525655
總結(jié)
以上是生活随笔為你收集整理的android锁屏唤醒并解锁屏幕的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。