Android:原因:android.view.WindowManager $ BadTokenException:无法添加窗口-令牌null不适用于应用程序

I make a FloatView like this site,https://github.com/JackZhous/FloatView

目标: 我想更改FloatView的图层,以便他现在指出该应用程序,而不是出现在主屏幕上。

问题: 我修改了文件... FloatUtil.java第81行mParams.type = WindowManager.LayoutParams.TYPE_PHONE; -> FloatUtil.java第81行mParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;

得到错误

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.jack.zhou.floatview, PID: 15188
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jack.zhou.floatview/com.jack.zhou.floatview.MainActivity}: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
    at android.app.ActivityThread.access$800(ActivityThread.java:153)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5293)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
 Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
    at android.view.ViewRootImpl.setView(ViewRootImpl.java:569)
    at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:282)
    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
    at com.jack.zhou.floatview.floatutil.FloatUtil.createFloatView(FloatUtil.java:90)
    at com.jack.zhou.floatview.MainActivity.onCreate(MainActivity.java:39)
    at android.app.Activity.performCreate(Activity.java:5990)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2280)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392) 
    at android.app.ActivityThread.access$800(ActivityThread.java:153) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:135) 
    at android.app.ActivityThread.main(ActivityThread.java:5293) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:372) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 

我该如何解决?

评论