Android 8.0悬浮窗适配问题 报错:android.view.WindowManager$BadTokenException: Unable to add window android.vie

Android 8.0下同下开启悬浮窗报错

      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782)
  Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@fb36a92 -- permission denied for window type 2002

在网上看了好多又说权限问题,但是我加上权限还是会崩溃,最后通过修改WindowManager.LayoutParams的type解决问题
增加代码:

 private WindowManager.LayoutParams mParams;
 ...
 if (Build.VERSION.SDK_INT > 25) {
                    mParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
                } else {
                    mParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
                }

你可能感兴趣的:(Android)