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.

Reed
  • 14,703
  • 8
  • 66
  • 110
  • Do you want to unlock the phone and show the activity or just launch it in background and wait until user unlocks the phone? – Erol Aug 08 '12 at 03:21
  • 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) – Reed Aug 08 '12 at 21:10
  • @Jakar Can you download "WinAmp" from the market, [activate the LockScreen player](http://www.winamp.com/help/Android#Lock-screen_Player) and confirm that *that* is what you're trying to archive? – Lukas Knuth Aug 14 '12 at 12:36

3 Answers3

1

override the function

public void onAttachedToWindow() {

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

this will bring your activity visible after unlocking.

Pramod J George
  • 1,723
  • 12
  • 24
  • 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). – Reed Aug 10 '12 at 05:16
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)

Mahendra Liya
  • 12,912
  • 14
  • 88
  • 114
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.

Chitranshu Asthana
  • 1,089
  • 8
  • 19