3

I'm trying to open a view with WindowManager, a view that will be above all the activities of my app, but not above other apps.

This is what i have so far:

WindowManager.LayoutParams layOutParams = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.TYPE_PHONE,
                    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                    PixelFormat.TRANSPARENT);

layOutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
layOutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
LayoutInflater layOutInflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
View viewAboveAllActivities = layOutInflater.inflate(R.layout.activity_flash_alert_layout, null);

wm = (WindowManager) context.getSystemService(WINDOW_SERVICE);
wm.addView(viewAboveAllActivities, layOutParams);

I have no idea what are the right layout params that will fit my needs, hope you guys can help.

liranahum
  • 143
  • 3
  • 13
  • you should use **WindowManager.LayoutParams.TYPE_APPLICATION** as type instead of WindowManager.LayoutParams.TYPE_PHONE. this will make your view as application-level view. – okarakose May 25 '17 at 10:32
  • Tried that already, after changing to another activity the view disappeared.. – liranahum May 25 '17 at 10:34
  • well, maybe use **WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY**. reference : https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#TYPE_APPLICATION_OVERLAY – okarakose May 25 '17 at 10:36
  • How do you then add `viewAboveAllActivities` to your hierarchy? – azizbekian May 25 '17 at 10:38
  • WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY doesn't give me a touch event on the view. – liranahum May 25 '17 at 10:42
  • After creating the view i call the WindowManager object and call addView.. – liranahum May 25 '17 at 10:43

0 Answers0