WindowManager$BadTokenException unable to add window

萝らか妹 提交于 2019-11-28 13:19:16
08-23 15:38:21.021: E/AndroidRuntime(4200): Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@418c0b68 -- permission denied for this window type

Problem: Permission missing in maifest file.

Solution: Use following permission in AndroidManifest.

android.permission.SYSTEM_ALERT_WINDOW

if your application apiLevel >= 19, don't use

WindowManager.LayoutParams.TYPE_PHONE or WindowManager.LayoutParams.TYPE_SYSTEM_ALERT

you can use

LayoutParams.TYPE_TOAST

or

TYPE_APPLICATION_PANEL

now my code for LayoutParams is like,

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

Starting from marshmallow versions the permission approval is a little bit complex. So even after giving the above permission this issue is not resolved. Please see the following link.

Unable to add window android.view.ViewRoot$W@44da9bc0 -- permission denied for this window type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!