Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在窗口中添加视图错误_Java_Android - Fatal编程技术网

Java 在窗口中添加视图错误

Java 在窗口中添加视图错误,java,android,Java,Android,我有以下代码 WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams(); localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; localLayoutParams.gravity = Gravity.TOP; localLayoutPar

我有以下代码

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清单
Android.permission.SYSTEM\u ALERT\u窗口中添加了这个

我得到了这个错误:
android.view.WindowManager$BadTokenException:无法添加windowandroid.view.ViewRootImpl$W@1028c5e--拒绝对窗口类型2010的权限


我在API23仿真器中对此进行了测试。我知道这是一个权限问题,我如何处理它?

从SDK开始,从PlayStore下载的23个应用程序将自动授予此权限,您需要用户手动启用“绘制其他应用程序”设置我如何实现?你能解释一下吗?我查一下,谢谢@MatPag