WindowManager$BadTokenException: Unable to add window permission denied for this window type

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WindowManager$BadTokenException: Unable to add window permission denied for this window type相关的知识,希望对你有一定的参考价值。

10-11 11:47:27.472: E/androidRuntime(12804): java.lang.RuntimeException: Unable to start activity ComponentInfo{cn.zhl.classguiding/cn.zhl.classguiding.XueanPdfActivity}: android.view.WindowManager$BadTokenException: Unable to add window [email protected] -- permission denied for this window type
10-11 11:47:27.472: E/AndroidRuntime(12804): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
10-11 11:47:27.472: E/AndroidRuntime(12804): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
10-11 11:47:27.472: E/AndroidRuntime(12804): at android.app.ActivityThread.access$600(ActivityThread.java:123)
10-11 11:47:27.472: E/AndroidRuntime(12804): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
10-11 11:47:27.472: E/AndroidRuntime(12804): at android.os.Handler.dispatchMessage(Handler.java:99)
10-11 11:47:27.472: E/AndroidRuntime(12804): at android.os.Looper.loop(Looper.java:137)
10-11 11:47:27.472: E/AndroidRuntime(12804): at android.app.ActivityThread.main(ActivityThread.java:4424)
10-11 11:47:27.472: E/AndroidRuntime(12804): at java.lang.reflect.Method.invokeNative(Native Method)
10-11 11:47:27.472: E/AndroidRuntime(12804): at java.lang.reflect.Method.invoke(Method.java:511)
10-11 11:47:27.472: E/AndroidRuntime(12804): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
10-11 11:47:27.472: E/AndroidRuntime(12804): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
10-11 11:47:27.472: E/AndroidRuntime(12804): at dalvik.system.NativeStart.main(Native Method)
10-11 11:47:27.472: E/AndroidRuntime(12804): Caused by: android.view.WindowManager$BadTokenException: Unable to add window [email protected] -- permission denied for this window type
10-11 11:47:27.472: E/AndroidRuntime(12804): at android.view.ViewRootImpl.setView(ViewRootImpl.java:537)
10-11 11:47:27.472: E/AndroidRuntime(12804): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:301)
10-11 11:47:27.472: E/AndroidRuntime(12804): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
10-11 11:47:27.472: E/AndroidRuntime(12804): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
10-11 11:47:27.472: E/AndroidRuntime(12804): at android.view.Window$LocalWindowManager.addView(Window.java:537)
10-11 11:47:27.472: E/AndroidRuntime(12804): at cn.zhl.classguiding.XueanPdfActivity.createFloatView(XueanPdfActivity.java:1854)
10-11 11:47:27.472: E/AndroidRuntime(12804): at cn.zhl.classguiding.XueanPdfActivity.onCreate(XueanPdfActivity.java:415)
10-11 11:47:27.472: E/AndroidRuntime(12804): at android.app.Activity.performCreate(Activity.java:4465)
10-11 11:47:27.472: E/AndroidRuntime(12804): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
10-11 11:47:27.472: E/AndroidRuntime(12804): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
10-11 11:47:27.472: E/AndroidRuntime(12804): ... 11 more

 

 

修改方法:manifest.xml 添加权限

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" /> 

以上是关于WindowManager$BadTokenException: Unable to add window permission denied for this window type的主要内容,如果未能解决你的问题,请参考以下文章

WindowManager 中的全屏

WindowManager.LayoutParams 详解(转载)

WindowManager的简单了解

Android WindowManager悬浮窗:不需要申请权限实现悬浮

WindowManager 简单悬浮框的实现

WindowManager 简单悬浮框的实现