Android Question [Solved] Overlay button not working at SDK level 30

AndroidMadhu

Active Member
Licensed User
Hello,
I am following the below link for overlay button...
https://www.b4x.com/android/forum/threads/chathead-wrapper-gif-overlay.62027/

But the above links support the SDK version min 14 and Target SDK 21.

While I am using min 14 and target SDK 30 the above wrapper throwing below error

B4X:
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at b4a.example.oservice.handleStart(oservice.java:111)
at b4a.example.oservice.access$000(oservice.java:19)
at b4a.example.oservice$1.run(oservice.java:82)
at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.onStartCommand(ServiceHelper.java:237)
at b4a.example.oservice.onStartCommand(oservice.java:80)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4415)
at android.app.ActivityThread.access$1800(ActivityThread.java:270)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7948)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@bec790e -- permission denied for window type 2002
at android.view.ViewRootImpl.setView(ViewRootImpl.java:1147)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:439)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:95)
at b4a.example.oservice$CustomImageView.sharedConstructing(oservice.java:697)
at b4a.example.oservice$CustomImageView.<init>(oservice.java:665)
at b4a.example.oservice.newInstance2(oservice.java:831)


Please advice on this please...

Thanks
 

agraham

Expert
Licensed User
Longtime User
Probably lacking the SYSTEM_ALERT_WINDOW permission
Manifest.permission | Android Developers
SYSTEM_ALERT_WINDOW - How to get this permission automatically on Android 6.0 and targetSdkVersion 23 - Stack Overflow

The following is my best guess - others may have a better understanding of this!

Add the manifest entry
AddPermission(android.permission.SYSTEM_ALERT_WINDOW)

You may need to ask for the permission at runtime.
Dim rp As RuntimePermissions
rp.CheckAndRequest("android.permission.SYSTEM_ALERT_WINDOW")
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
 
Upvote 0
Top