我正在开发一个应用程序,用于替换安卓设备上的默认锁屏(滑动以解锁)。我成功地通过禁用钥匙保管员并使用屏幕关闭和屏幕打开意图广播接收器显示我的活动来实现此操作。现在,问题是当我出于任何原因重新设置默认屏幕锁定时,除非我强制关闭并重新启动应用程序,否则我的应用程序将无法禁用钥匙保护。
km = (KeyguardManager) getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE);
if( km.inKeyguardRestrictedInputMode()) {
//it is locked
km = (KeyguardManager) getApplicationContext().getSystemService(KEYGUARD_SERVICE);
kl=km.newKeyguardLock("com.example.helloworld.MainActivity");
kl.disableKeyguard();
} else {
Intent i = getIntent();
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(i);
}