在Window中添加视图错误

时间:2017-07-14 16:29:52

标签: java android

我有以下代码

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);

我在Android Manifestandroid.permission.SYSTEM_ALERT_WINDOW

中添加了此内容

我收到了这个错误:android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@1028c5e -- permission denied for window type 2010

我在API 23模拟器中测试它。我知道这是一个许可问题,我该如何处理呢?

0 个答案:

没有答案