I want to be able to start an Activity that is not part of my app while the device is password locked. How could I do this, if it's even possible?
Note: I am well aware of putting getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
within the onCreate
of my activity. This will not work, though, as I'm not starting my own activity, but a 3rd party one that is outside of my app.
Here's how to open your favorite apps directly from the Lock screen on your Galaxy device: Go to Settings > Lock screen > Shortcuts. Tap Left shortcut and pick your desired app. Do the same for Right shortcut.
It's advised to use NotificationManager. IMPORTANCE_HIGH for increasing the chances of the notification appearing as a heads up notification. We also change the lockscreenVisibility to Notification. VISIBILITY_PUBLIC to tell Android that the notification can be shown on the lock screen.
To enable it you have to go to the app configuration -> Other permissions -> Show On Lock screen.
Update: If you want to show the Activity on the lock screen, you need to set showForAllUsers to true. Here's the description from the Android documentation: Specify that an Activity should be shown even if the current/foreground user is different from the user of the Activity. This will also force the android.
It will not work if you are trying to launch any third party app over lock screen. As you have observed yourself, you need to set the window flag to ensure that activity get launched over lock screen, there is no way to ensure the activity from other third party app are also setting the same flag.
In case you are building a feature bundle where each feature is nothing but a different application then you will have to ensure that all the entry points of those feature do set this window flag. Best thing would be to declare a BaseActivity which sets proper flag on creation and let all the feature dev team use this as base class for entry points.
override the function
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
this will bring your activity visible after unlocking.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With