Android launch intent when lockscreen should appea

2019-07-18 02:46发布

问题:

I am trying to develop a alternate lock screen there for I need a intent filter which listens on the screen going off

but the problem is I don't know which attribute to use and which value to give

回答1:

Working on the same thing as well.

this is the question i posted yesterday, follow it maybe something will pop out.

By the way as i wrote in the question, the action you have to listen to are:

  • Intent.ACTION_SCREEN_ON: screen is on, you have to start your activity here and check for inKeyguardRestrictedInputMode this method to be sure that the keyguard ( lockscreen ) is open.
  • Intent.ACTION_SCREEN_OFF: this is the event sent when the screen goes off, do whatever you need here.
  • Intent.ACTION_USER_PRESENT: this is instead sent when the user unlock the secure keyguard like.

An important thing to know are these 2 flangs:

  • WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED:
  • WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD

use them in your lockscreen activity to be able to have it when the screen is locked and to dismiss keyguards when they are not secure.

hope this help, there is a huge lack of documentation on android lockscreen customization.



回答2:

You need an InternFilter that listens to Intent.ACTION_SCREEN_OFF action.

IntentFilter screenFilter = new IntentFilter();
screenFilter.addAction(Intent.ACTION_SCREEN_OFF);