I need to draw a system overlay view from a service. This is the part that adds this view to WindowManager:
WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
It failed with permission denied exception:
Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@f15e8de -- permission denied for window type 2038
I have tried everything I found online and still not able to get this permission to pass.
- I have SYSTEM_ALERT_WINDOW in manifest.
- I have to use TYPE_APPLICATION_OVERLAY and not any other TYPE.
- I checked
Settings.canDrawOverlays
and it is true. - I checked my app has
Draw over other apps
permission enabled in App Settings.
I looked at all the answers in Android: permission denied for window type 2038 using TYPE_APPLICATION_OVERLAY but none of them solve my problem.
Any help is appreciated! Thanks!