16

Before today I would have said this is just not possible, to have an app that runs overlayed on top of everything else: home screens, apps, dialer, etc.

If you try the free application "Super Manager" it does exactly this. It has an icon and widget like screen that will show up always and everywhere. While the icon or widget is on the screen you can still interact with the app running behind it.

How is this possible and how can we recreate this functionality?

Update: Here is some images of it in action. You can see the overlayed application running as a small arrow on top of Dolphin. Then when you press it you can see the application running as a big widget kind of thing. Even while the widget is up you can still interact with the background app. In this example dolphin is the background app.

Image 1

alt text

Cameron McBride
  • 6,779
  • 11
  • 40
  • 52

3 Answers3

8

See this:

Creating a system overlay window (always on top)

Check the comment section of the accepted answer. You will find link to a working example project.

==EDIT==

Link to the project

Community
  • 1
  • 1
Sarwar Erfan
  • 18,034
  • 5
  • 46
  • 57
  • The example you mention almost works. The onTouch even gets triggered for the overlay AND the application that is running behind it. For example pressing the overlay that is on top of an icon triggers the icon behind it. In the Super Manager example the activity running behind does not get triggered. – Cameron McBride Jan 17 '11 at 18:39
  • Please link directly to the example project, vice sending us on a wild goose chase! – Rubber Duck Jan 24 '14 at 15:07
  • @RubberDuck: Link added. Just a note, I am going to update that project next week. I shall post the updated project link here. I actually need to update for another project I am working on. – Sarwar Erfan Jan 24 '14 at 15:21
5

Starting from Android 4.x, Android team Android team fixed a potential security problem by adding a new function adjustWindowParamsLw() in which it will add FLAG_NOT_FOCUSABLE, FLAG_NOT_TOUCHABLE and remove FLAG_WATCH_OUTSIDE_TOUCH flags for TYPE_SYSTEM_OVERLAY window.

That's TYPE_SYSTEM_OVERLAY window won't receive any touch event on ICS platform and, of course, to use TYPE_SYSTEM_OVERLAY is not workable on ICS or future devices.

Updated: 2016/5/4 TYPE_TOAST cannot receive touch events on Android 4.0~4.3. It's the same as TYPE_SYSTEM_OVERLAY. On Android 4.4+, TYPE_TOAST removed from the excluded list, so you can also use TYPE_TOAST to receive touch events on Android 4.4+ devices.

Sam Lu
  • 3,448
  • 1
  • 27
  • 39
4

This can be done by a combination of things. The initial button is done by creating a window of type TYPE_SYSTEM_OVERLAY . These windows cannot gain focus, however you can use FLAG_WATCH_OUTSIDE_TOUCH to get touch events and match up the coordinates to realized you've been touched.

Similarly there is http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#TYPE_SYSTEM_ALERT (And TYPE_SYSTEM_DIALOG).

Finally, an activity can be created with http://developer.android.com/reference/android/R.style.html#Theme_Translucent (or variants).

Kevin TeslaCoil
  • 10,037
  • 1
  • 39
  • 33
  • How would you get the translucent activity to allow interaction with a separate application running behind it? When I have created a popup box activity the activity behind it could not be touched. In the app above the application running can still be interacted with. For example the dolphin browser can still be scrolled while the Super Manager has its activity on top. – Cameron McBride Jan 17 '11 at 03:37
  • I think you want a SYSTEM_ALERT with FLAG_NOT_TOUCH_MODAL instead of a translucent activity then – Kevin TeslaCoil Jan 17 '11 at 05:33