-6

I encountered a problem,

  • MyActivity is under the LockScreen, in this case, I need to launch MyActivity from framework by clicking volume button;
  • MyActivity is on the top of Lockscreen, in this case, I do nothing.

But I don't know how to distinguish this two situations in framework. I know how to get the top activity, however, LockScreen isn't a activity.

I have a temporary solution, if MyActivity has LayoutParams.FLAG_SHOW_WHEN_LOCKED property, set a custom system property, so I know whether launch MyActivity by this custom system property, but I don't think this is good.

I want to know whether there is a better solution.

William
  • 1
  • 2

1 Answers1

0

Register BroadcastReceiver "android.intent.action.USER_PRESENT" in CameraActivity and detect whenever screen unlock event happens. Than Based on your requirement you can manage your code.

USER_PRESENT Receiver

in your MainActivity inside oncreate you can check whether screen is locked or not

KeyguardManager keyguardManager = (KeyguardManager) 
context.getSystemService(Context.KEYGUARD_SERVICE);
if( keyguardManager .inKeyguardRestrictedInputMode()) {
 //it is locked
} else {
 //it is not locked
}
  • I know this method, but the more important thing is that I need to distinguish this case in third app, in this two situations, `inKeyguardRestrictedInputMode()` will all return true. Thanks anyway. – William Mar 27 '18 at 01:01