Android Question Why doesn't Fire OS detect overlay permission in B4A apk, but it does for another apk?

JohnC

Expert
Licensed User
Longtime User
I am trying to write a simple app for Fire OS 7 (Android 9) and it requires the overpay permission (SYSTEM_ALERT_WINDOW).

When I go to install the B4A generated APK (using the below manifest code), the fire os installer says "no special permissions are requested from this app":

B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")

AddPermission(android.permission.SYSTEM_ALERT_WINDOW

But when I install another company's APK that also requests the overlay permission, the fire os properly displays "this app will draw over other apps" permission *before* it installs the APK, so obviously it is reading the APK's manifest which is:

B4X:
<?xml version="1.0" encoding="UTF-8"?>
-<manifest platformBuildVersionName="9" platformBuildVersionCode="28" package="com.xxx.xx" android:installLocation="preferExternal" android:compileSdkVersionCodename="9" android:compileSdkVersion="28" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-feature android:required="false" android:name="android.hardware.touchscreen"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>

So what is different about the B4A generated APK that causes fire os to not see that it requires the overlay permission?

I am asking because even if I try to use Erel's code (at https://www.b4x.com/android/forum/threads/draw-on-top-of-other-apps-permission.90513/), I am getting a "onActivityResult: wi is null" error. So I want to fix this first issue (of the installer not recognizing the overlay permission) first, then see if the "onActivityResult: wi is null" error goes away because that other company's app doesn't pop-up a permission settings dialog when it's run in order to display the overlay - it just displays the overlay - so maybe with fire os it doesn't need to display a settings dialog to do overlays and just the permission in the manifest is needed to do overlays.
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
The "wi is null" issue is probably not related to the permission. It happens when the app is killed while it is in the background. You can start a foreground service as a test.

So what is different about the B4A generated APK that causes fire os to not see that it requires the overlay permission?
You can see the generated AndroidManifest.xml in the objects folder. There is nothing special with the APK.

Maybe the other app is whitelisted.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
I get the "wi is null" error when I click the button to get the overlay permission as in your example that I linked to (so it is not a service) - I'm thinking maybe that the fire os doesn't have a settings dialog for that particular permission, and that is why an attempt to display that settings dialog is killed?

I'm also thinking that maybe under fire os an app only needs to obtain that particular permission from within the manifest, but for some reason it's not working with my B4A app (could it have something to do with me using B4A 9.01.2?)

Also, I don't think it is a whitelist issue because the app is NOT even offered in the Amazon App Store, so it would be strange for the OS to whitelist an app that amazon is not making any commission from because the app is using it's own payment processor:
 
Last edited:
Upvote 0

JohnC

Expert
Licensed User
Longtime User
I also noticed this...

In the other apps manifest, it has this main line with a lot of info that B4A does NOT generate:
B4X:
-<manifest platformBuildVersionName="9" platformBuildVersionCode="28" package="com.xxx.xxx" android:installLocation="preferExternal" android:compileSdkVersionCodename="9" android:compileSdkVersion="28" xmlns:android="http://schemas.android.com/apk/res/android">

So, since I am trying to figure out why the other app's overlay works correctly, but my B4A doesn't, I would like to try adding all the info from the other app's manifest that is missing from B4A's manifest and add it to the B4A manifest to see if it helps fix this issue. So, is there a way I can add the above manifest text to the B4A generate manifest as a test to see if it works?

Also, the B4A generated manifest adds the below line to it's manifest file, but why is it missing from the other app's manifest file?:
B4X:
<uses-sdk android:targetSdkVersion="26" android:minSdkVersion="21"/>
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
I think I have a handle on the issue - It looks like I am doing something wrong when I am calling the overlay window function.
 
Last edited:
Upvote 0

OliverA

Expert
Licensed User
Longtime User
I am getting a "onActivityResult: wi is null" error

As much as I remember, I may have had the same issues as you when it came to requesting draw-over permission. While testing the code, I noticed that when starting the system activity to request permission, my activity went into the background. Once the user returned from the system permission screen, my activity was resumed and Activity_Resume was invoked. Therefore, I did my draw-over check right after Activity_Resume, split it into two functions, and did not use the StartActivityForResult function provided by @Erel in the original example.

B4X:
Sub Activity_Resume
    If Not(HasDrawOverPermission) Then
        GetDrawOverPermission
    End If
'Remaining Activity_Resume code below
'
End Sub

'https://www.b4x.com/android/forum/threads/draw-on-top-of-other-apps-permission.90513/#content
Private Sub HasDrawOverPermission As Boolean
    
    Dim phone As Phone
    Dim retVal As Boolean = True
    
    If phone.SdkVersion >= 23 Then
        Dim settings As JavaObject
        settings.InitializeStatic("android.provider.Settings")
        Dim ctxt As JavaObject
        ctxt.InitializeContext
        retVal = settings.RunMethod("canDrawOverlays", Array(ctxt))
    End If
    
    Return retVal
End Sub

Private Sub GetDrawOverPermission
        Dim intent2 As Intent
        'Note this in Android's developer docs (https://developer.android.com/reference/android/provider/Settings):
        'Input: Optionally, in versions of Android prior to 11, the Intent's data URI can specify the application
        'package name to directly invoke the management GUI specific to the package name. For example "package:com.my.app".
        'Notice the "prior to 11"
        'WARNING: Below will blow up pre-API 23. Use only in conjunction with return value of False of HasDrawOverPermission
        intent2.Initialize("android.settings.action.MANAGE_OVERLAY_PERMISSION", $"package:${Application.PackageName}"$)
        StartActivity(intent2)
End Sub

It looks like I am doing something wrong when I am calling the overlay window function because the overlay demo does work on the Firestick correctly without having to ask for permission via the settings dialog.
If a previous launch of your test application brought up the settings screen and you approved the overlay, then when updating your app, it should keep the setting and your app will just work (without invoking the settings screen again). The 'I am getting a "onActivityResult: wi is null" error' error happens AFTER the settings screen is done (and you have approved the permission). Uninstall your app and re-install it and see if the code you previously used still works.

So what is different about the B4A generated APK that causes fire os to not see that it requires the overlay permission?
Apps installed via a Store (be it Google or Amazon) may display permission screens during the installation of the applications (and before the application is actually started). Applications side-loaded do not get that service. Side-loaded apps always request permission during run-time.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
I got it working :)
 
Last edited:
Upvote 0

Sheshnath

New Member
I got it working, but I had to trick the OS to do it, and it doesn't ask for the permission, but now at least the installer does see the overylay permission in the APK.
Hi JohnC, Now I am in the same situation, what trick you used? Fire OS 7 (Android 9) don't have overlay permission hence my app auto launch on reboot not working
 
Upvote 0
Top