Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start external activity while phone is locked

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.

like image 786
Reed Avatar asked Aug 05 '12 16:08

Reed


People also ask

How can I open apps when my phone is locked?

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.

How do I show activity on lock screen instead of notification?

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.

How do I show activity on lock screen?

To enable it you have to go to the app configuration -> Other permissions -> Show On Lock screen.

How wake up device and show an activity on top of lock screen for alarm?

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.


2 Answers

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.

like image 158
Chitranshu Asthana Avatar answered Oct 10 '22 04:10

Chitranshu Asthana


override the function

public void onAttachedToWindow() {

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

this will bring your activity visible after unlocking.

like image 41
Pramod J George Avatar answered Oct 10 '22 05:10

Pramod J George