gpt4 book ai didi

android - 在 KeyguardRestrictedInputMode() 中返回失败结果

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:46:56 29 4
gpt4 key购买 nike

我有一个函数可以确定手机屏幕的四种状态:屏幕打开、屏幕关闭、屏幕打开并锁定、屏幕打开但未锁定。我的功能是

private KeyguardManager keyguardManager;
public String getScreenStatus()
{
String sreen_State="unknown";
keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
if (pm.isInteractive()) {
sreen_State="screen_on";
if(!keyguardManager.inKeyguardRestrictedInputMode()) {
sreen_State="screen_on_no_lock_screen";

}else{
Log.i(TAG, "screen_on_lock_screen");
sreen_State="screen_on_lock_screen";
}
}
else {
sreen_State="screen_off";
}
}
else if(Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT_WATCH){
if(pm.isScreenOn()){
sreen_State="screen_on";
if(!keyguardManager.inKeyguardRestrictedInputMode()) {
Log.i(TAG, "screen_on_no_lock_screen");
sreen_State="screen_on_no_lock_screen";

}else{
Log.i(TAG, "screen_on_lock_screen");
sreen_State="screen_on_lock_screen";
}

}
else {
mIsScreenOn=false;
sreen_State="screen_off";
}
}
return sreen_State;
}

上述函数返回屏幕的更正状态。但是,当我添加如下代码时,它出错了:

 KeyguardManager.KeyguardLock
kl = keyguardManager.newKeyguardLock("MyKeyguardLock");
if(index.equals("1"))
kl.disableKeyguard();
else if(indexequals("2"))
kl.reenableKeyguard();
getScreenStatus();

索引可以通过按一个按钮来改变。现在,错误的屏幕状态发生了。它总是返回 screen_on_lock_screen,尽管屏幕处于 screen_on_no_lock_screen。我该如何解决我的问题?

最佳答案

自 API 级别 13 起,不推荐使用 KeyguardManager.NewKeyguardLock。您是否尝试过使用 WindowManager.LayoutParams 的 FLAG_DISMISS_KEYGUARDFLAG_SHOW_WHEN_LOCKED

This class was deprecated in API level 13. Use FLAG_DISMISS_KEYGUARD and/or FLAG_SHOW_WHEN_LOCKED instead; this allows >you to seamlessly hide the keyguard as your application moves in and out of >the foreground and does not require that any special permissions be requested. >Handle returned by newKeyguardLock(String) that allows you to disable / >reenable the keyguard.

此处的链接形式为 Android documentation .

希望对您有所帮助!

关于android - 在 KeyguardRestrictedInputMode() 中返回失败结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39704274/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com