11

I'm currently having a hard time displaying a TYPE_SYSTEM_ALERT window in fullscreen mode. I'd like to do so in order to have an overlay view, created from a service, on top of the status bar but without hiding it.

However, putting the FLAG_FULLSCREEN flag in the layout params of the window I'm creating doesn't seem to work. I found the STATUS_BAR and EXPAND_STATUS_BAR permissions but I couldn't find how to make use of them.

Here are the LayoutParams :

    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
            WindowManager.LayoutParams.FLAG_FULLSCREEN,
            PixelFormat.TRANSLUCENT);

    params.gravity = Gravity.RIGHT | Gravity.TOP;

    mWindowManager.addView(mOverlayView, params);

Any ideas?

Thank you

Toop
  • 291
  • 1
  • 2
  • 8
  • I've been using a similar technique to render a picture-in-picture video stream over any application. However, the update rate of the View made with your method with seems to be tied to the update rate of the views beneath it. Do you know if there's a way to decouple the update rates and maximize the update rate of the transparent overlay? – user48956 Jan 19 '12 at 01:22

2 Answers2

18

I found the solution while trying to do something else!

In order to have a TYPE_SYSTEM_ALERT window on top of every other window AND on top of the status bar you must add the FLAG_LAYOUT_IN_SCREEN flag and not the FLAG_LAYOUT_FULLSCREEN flag :

WindowManager.LayoutParams params = new WindowManager.LayoutParams(
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
        WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
        PixelFormat.TRANSLUCENT);

mWindowManager.addView(mOverlayView, params);
Toop
  • 291
  • 1
  • 2
  • 8
  • 1
    The status bar is still able to be pulled down. I changed the PixelFormat to OPAQUE so I could see the new view and it does cover the status bar, however when i swipe down from the top of the screen the status still expands and is clickable. Any ideas? – MindWire Dec 08 '11 at 14:44
  • very helpful! I was looking for a way to create an emulated cursor, like was possible on Windows Mobile, and thank to your help, I have it – radhoo Apr 27 '12 at 13:52
  • 1
    Works for the status bar. Any idea how to make it on top of the navigation bar also? – Alex Vang Sep 12 '15 at 14:34
4

It doesn't work anymore in Ice Cream Sandwich. The Status bar covers a TYPE_SYSTEM_ALERT window. But TYPE_SYSTEM_OVERLAY still works fine.

Verbeia
  • 4,370
  • 2
  • 20
  • 44
deviant
  • 3,103
  • 2
  • 29
  • 43
  • 1
    Oh course that is a problem because OVERLAY's do not accept MotionEvents the same way, only with the WATCH_TOUCH_OUTSIDE flag, and all events will have an action of ACTION_OUTSIDE. – Tom Feb 23 '12 at 15:42