How do I programmatically change the type of WindowManager.LayoutParams?

I got a view of what I can display on the locked screen. But I want this to become optional. I am currently using these options to achieve this goal:

WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT, 
WindowManager.LayoutParams.WRAP_CONTENT, 
WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, 
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | 
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | 
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, PixelFormat.TRANSPARENT);

      

And in order not to show it on the lockscreen, I use

WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT, 
WindowManager.LayoutParams.WRAP_CONTENT, 
WindowManager.LayoutParams.TYPE_PHONE, 
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | 
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | 
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, PixelFormat.TRANSPARENT);

      

Individually they work fine, but I want to programmatically change the type and flags. So I tried to change WindowManager.LayoutParams with

params.flags &= ~WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
params.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
params.flags |= WindowManager.LayoutParams.TYPE_PHONE;
windowManager.updateViewLayout(myView,params);

      

to remove the type, remove the flag and set the new type, but that doesn't seem to work. Does anyone know how to do this correctly?

+3


source to share


1 answer


You set values type

to flag

. Try this instead:



params.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;

// type is no bit flag, so this should do it
params.type = WindowManager.LayoutParams.TYPE_PHONE;

      

+2


source







All Articles