有关我的应用程序,我需要知道屏幕被锁定。如何成问题检查。我用下面的标记:
For my application, I need to know that the screen is locked. How to check this in problematically. I used following flag:
if(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON != 0){
// some code
}else if((WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED)!= 0){
// some code
}
但是,这总是既执行if和else部分......我必须使用来检查屏幕被锁定或没有?这标志
But this always executing both if and else part... which flag I have to use to check the screen is locked or not?
推荐答案
我会尽力回答这个虽然这个问题已经是老,因为它是未得到解决,帮助其他谷歌。 ;)
I'll try to answer this though the question is already old since it is unresolved and could help other googlers. ;)
首先,你必须注册一个BroadcastReceiver的Intent.ACTION_SCREEN_OFF和放大器; Intent.ACTION_SCREEN_ON。请注意,此接收器必须在codeS注册,还可以在清单中声明将无法工作。
First you must register a BroadcastReceiver for Intent.ACTION_SCREEN_OFF & Intent.ACTION_SCREEN_ON. Note that this receiver must be registered in codes and will not work when declared in the manifest.
在你的广播接收器,当您收到Intent.ACTION_SCREEN_ON,您可以检查屏幕是使用下面的codeS锁定:
In your broadcast receiver, when you receive Intent.ACTION_SCREEN_ON, you can check if the screen is locked by using the below codes:
KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
boolean locked = km.inKeyguardRestrictedInputMode();
相关推荐
最新文章