Android判断屏幕状态与屏幕解锁和锁定

主动判断屏幕是否亮着:

public boolean isScreenOn(Context context) { 
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); 
    if (pm.isScreenOn()) { 
        return true; 
    } 

    return false; 

//屏幕解锁 
KeyguardManager keyguardManager = (KeyguardManager)getSystemService(KEYGUARD_SERVICE); 
KeyguardLock keyguardLock = keyguardManager.newKeyguardLock(LOCK_TAG); 
keyguardLock.disableKeyguard(); 
//屏幕锁定 
keyguardLock.reenableKeyguard(); 


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对象,后面的参数|表示同时传入两个值,最后的是LogCat里用的Tag  
        PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK,"bright");  
        //点亮屏幕  
        wl.acquire();  
        //释放  
        wl.release();  

展开阅读全文

没有更多推荐了,返回首页