无法添加窗口 - 窗口类型2003的权限被拒绝

时间:2018-02-05 11:03:26

标签: android android-windowmanager

我在尝试向WindowManager添加内容时遇到了问题。什么是最有趣的,如果你通过另一个编译器(AIDE)编译,那么一切正常。我现在正在使用Android工作室。以下是代码:

params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_PHONE,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT);

        params.gravity = Gravity.TOP|Gravity.LEFT;
        params.x = 0;
        params.y = y - barHeight;

        windowManager.addView(nb, params); // error there

AndroidManifest:

<uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />

错误讯息:

java.lang.RuntimeException: Unable to create service priv.congard.ozonehd4k.controlpanel.NavigationBarService: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@a8744a7 -- permission denied for window type 2003
                                                                                         at android.app.ActivityThread.handleCreateService(ActivityThread.java:3226)
                                                                                         at android.app.ActivityThread.-wrap5(ActivityThread.java)
                                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1586)
                                                                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                         at android.os.Looper.loop(Looper.java:154)
                                                                                         at android.app.ActivityThread.main(ActivityThread.java:6186)
                                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
                                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
                                                                                      Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@a8744a7 -- permission denied for window type 2003
                                                                                         at android.view.ViewRootImpl.setView(ViewRootImpl.java:703)
                                                                                         at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:342)
                                                                                         at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:94)
                                                                                         at priv.congard.ozonehd4k.controlpanel.NavigationBarService.onCreate(NavigationBarService.java:64)

another question不同,在我的情况下,窗口不是在锁定屏幕上创建的。 有什么奇怪的问题可以连接?

0 个答案:

没有答案