java.lang.RuntimeException: Unable to start service com.zshfzb.pop.MyService@41a76f10 with Intent { cmp=com.zshfzb/.pop.MyService }:
android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@41a6c108 -- permission denied for this window type
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2515)
at android.app.ActivityThread.access$1900(ActivityThread.java:133)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1300)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4794)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@41a6c108 -- permission denied for this window type
at android.view.ViewRootImpl.setView(ViewRootImpl.java:609)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:326)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
at com.zshfzb.pop.MyWindowManager.show(MyWindowManager.java:69)
at com.zshfzb.pop.MyService.onStartCommand(MyService.java:46)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2498)
... 10 more
解决办法添加:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" />