Start external activity when the phone is locked

I want to be able to run an Activity that is not part of my application when the device is locked with a password. How can I do this if possible?

Note. I am well aware of the placement of getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); in onCreate my activity. However, this will not work, because I am not starting my own activity, but a third-party one, which is outside my application.

+6
source share
3 answers

This will not work if you try to run a third-party application on top of the lock screen. As you yourself have noticed, you need to set the window flag to make sure that the activity is launched on the lock screen, there is no way to guarantee that the activity of another third-party application also sets the same flag.

If you are creating a set of functions in which each function is nothing but a different application, you will need to make sure that all the entry points of this function set this window flag. It would be best to declare BaseActivity, which sets the correct flag at creation, and let the entire function development team use this as a base class for entry points.

+1
source

override function

 public void onAttachedToWindow() { this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD); super.onAttachedToWindow(); } 

this will cause your activity to be visible after unlocking.

+1
source

This is only possible if the actual developer wrote the code by overriding the onAttachedToWindow() method in the action you are trying to open from your application.

If not, then, unfortunately, you have no way to do what you are trying to do (regarding the latest APIs)

+1
source

Source: https://habr.com/ru/post/922167/


All Articles