Start external activity while phone is locked
Asked Answered
D

3

6

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.

Dysentery answered 5/8, 2012 at 16:20 Comment(3)
Do you want to unlock the phone and show the activity or just launch it in background and wait until user unlocks the phone?Slowdown
The phone will remain locked, as it is password protected. But I want to launch the activity in the foreground (in front of the lock screen)Dysentery
@Jakar Can you download "WinAmp" from the market, activate the LockScreen player and confirm that that is what you're trying to archive?Papillary
B
1

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.

Biolysis answered 14/8, 2012 at 9:14 Comment(0)
P
1

override the function

public void onAttachedToWindow() {

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

this will bring your activity visible after unlocking.

Preoccupied answered 8/8, 2012 at 12:27 Comment(1)
If I'm not mistaken, this will bring MY activity to the foreground, which I already had solved. See the Note in my question. I need to startActivity on a third-party app and bring it to the foreground (in front of the lock screen).Dysentery
C
1

This is only possible if the actual developer has written code by overriding the onAttachedToWindow() method in the activity you are trying to open from within your app.

If not, then, sorry to say, but you have no option to do what you are trying to do (as far as the recent APIs goes)

Crowning answered 14/8, 2012 at 9:13 Comment(0)
B
1

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.

Biolysis answered 14/8, 2012 at 9:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.