Search code examples
androidsdkandroid-windowmanager

Unable to add window Exception


I have this error in just android 5.1

 Unable to add window android.view.ViewRootImpl$W@1df76e3 -- the specified window type is not valid

this is the code :

wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    params = new WindowManager.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                    WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
                    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            PixelFormat.TRANSPARENT);
...
 wm.addView(relativeLayout, params);

Solution

  • add this permission in AndroidManifest.

    android.permission.SYSTEM_ALERT_WINDOW
    

    on API >= 23 see