本文主要是介绍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);
这篇关于Android判断屏幕状态与屏幕解锁和锁定的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!