0

I have the following code

WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
            localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
            localLayoutParams.gravity = Gravity.TOP;
            localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
                    WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | // this is to enable the notification to receive touch events
                    WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; // Draws over status bar

            localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
            localLayoutParams.height = (int) (50 * getResources()
                    .getDisplayMetrics().scaledDensity);
            localLayoutParams.format = PixelFormat.TRANSPARENT;

            customViewGroup view = new customViewGroup(this);

            manager.addView(view, localLayoutParams);

I add this in the Android Manifest : android.permission.SYSTEM_ALERT_WINDOW

And i got this error: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@1028c5e -- permission denied for window type 2010

I test this in API 23 emulator. I know it's a permission problem, how can I handle it?

Oscar Moncayo
  • 188
  • 6
  • 20

0 Answers0