android 點亮手機屏幕與屏幕解鎖方法

點亮手機屏幕
1.記得加權限<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
[html]
PowerManager pm = (PowerManager)getSystemService(POWER_SERVICE); 
PowerManager.WakeLock mWakelock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP |PowerManager.FULL_WAKE_LOCK, "WakeLock"); 
mWakelock.acquire();//喚醒屏幕 
//…… 
mWakelock.release();//釋放 

屏幕解鎖
1.記得加權限<uses-permission android:name="android.permission.DISABLE_KEYGUARD"></uses-permission>
[html]
//獲取一個鍵盤鎖對象 
KeyguardManager mManager = (KeyguardManager)getSystemService(KEYGUARD_SERVICE); 
KeyguardLock mKeyguardLock = mManager.newKeyguardLock("Lock"); 
//讓鍵盤鎖失效 
mKeyguardLock.disableKeyguard(); 

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。