Android Question Problem using start at boot with Android 10

Sergio83

Active Member
Licensed User
Longtime User
Hello all,
A few years ago, I developed a home automation server with many features, including Alexa.
It is supported by an Android TV box that I just upgraded from Android 8 to 10.
This application has a service with the start at boot option.
I know that version 10 supports this option, but the launched application does not go to foreground.
Is there a workaround?
I looked at the Erel application "MyLocation", without finding the solution to my problem.
Thank you in advance for your help
 

Sergio83

Active Member
Licensed User
Longtime User
Hello Sagenut,
I was aware of this new limitation, but not aware of this turnaround.
I'll try to implement this permission as soon as I can do and let you know.
Many thanks for your help!
 
Upvote 0

Sergio83

Active Member
Licensed User
Longtime User
Thanks for these informations.

I tried the workaround you suggested me in this way:

Manifest update:

Manifest:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

Then in my app:

Activity Create (firstime):
Dim c As RequestDrawOverPermission 'this is the name of the class
        c.Initialize
        Wait For (c.GetPermission) Complete (Success As Boolean)
        Log("Permission: " & Success)

Then I created the class:

Class RequestDrawOverPermission:
Sub Class_Globals
    Private ion As Object
    Private phone As Phone
End Sub

Public Sub Initialize
End Sub

Public Sub GetPermission As ResumableSub
    If phone.SdkVersion >= 23 Then
        Dim settings As JavaObject
        settings.InitializeStatic("android.provider.Settings")
        Dim ctxt As JavaObject
        ctxt.InitializeContext
        If settings.RunMethod("canDrawOverlays", Array(ctxt)) = True Then
            Return True
        End If
        Dim i As Intent
        i.Initialize("android.settings.action.MANAGE_OVERLAY_PERMISSION", "package:" & Application.PackageName)
        StartActivityForResult(i)
        Wait For ion_Event (MethodName As String, Args() As Object)
        Return settings.RunMethod("canDrawOverlays", Array(ctxt))
    Else
        Return True
    End If
End Sub

Private Sub StartActivityForResult(i As Intent)
    Dim jo As JavaObject = GetBA
    ion = jo.CreateEvent("anywheresoftware.b4a.IOnActivityResult", "ion", Null)
    jo.RunMethod("startActivityForResult", Array As Object(ion, i))
End Sub

Private Sub GetBA As Object
    Dim jo As JavaObject = Me
    Return jo.RunMethod("getBA", Null)
End Sub

My app stay in background after reboot. I tried sdk 29 and 34 same result, I got this message in the log:

Log:
onActivityResult: wi is null

But loging of:

Log("Permission: " & Success)

Never appear.

May be I'm wrong somewhere?
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Well, I have an old simple that was working before B4A 13 (I do not intend that the problem is in B4A).
I tried to recompile it before posting here and.............. I found it not working anymore.
Still trying to understand why.
Anyway I was reading something on Android Developers and it seems that from Android 15 the trick of the Draw on Top of other Apps (android.permission.SYSTEM_ALERT_WINDOW) will not work anymore.
Assuming that I understood it correctly.
I am not a professional and I like to code just for fun and to keep my brain at work, but when I think what would be to publish and maintain something on Google Play....... I would just like stop coding.
 
Last edited:
Upvote 0

Sergio83

Active Member
Licensed User
Longtime User
Thank you for your response.
Concerning the limitation since Android 15, it does not concern my problem, I am using Android 10.
As yours, my applications are for strictly personal use, so I am not affected by PlayStore related limitations.
 
Upvote 0

Sergio83

Active Member
Licensed User
Longtime User
Should I have to consider that this issue has to stay as is, with no turnaround? If yes, Android is becoming like a jail, not so shure it's a good new for Google ..
Just remember Windows vs Linux ...
 
Upvote 0

Sergio83

Active Member
Licensed User
Longtime User
My apps is a home automation server running on an Andorid TV box. In case of power down, when power will be up again my purpose is the automatic restarting of this apps and bring its activity to foreground

So Yes, I'm trying to start an activity from service which have been started at boot (option startatboot true).
At the time of now at power up my apps is launched and run in background. The question is how to bring it automaticaly to foreground.
 
Upvote 0

Sergio83

Active Member
Licensed User
Longtime User
Hello Erel,
In addition to the code suggested by Sagenut I've added the SYSTEM_ALERT_WINDOW rp, both in the manifest and in the firstime activycreate section:

Manifest:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

ActivityCreate (FirstTime section):
rp.CheckAndRequest("android.permission.SYSTEM_ALERT_WINDOW")
   Wait For Activity_PermissionResult (Permission As String, ResultRP As Boolean)
At start of my app there are the requests for the rp's h've set up except for SYSTEM_ALERT_WINDOW.

Where am I wrong?
 
Upvote 0

Sergio83

Active Member
Licensed User
Longtime User
Erel, have a look to post #5.
You'll see that it was exactly what I've done except that the getpermission is request in the FirstTime section of ActivityCreate instead of by clicking a button.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
I share here my minimal example that stopped working for me.
At least you can try so it will help me understand if it's a my device problem or something else.
Click the button to request the permission the first time.
It will bring you to a page where you have to manually allow the app to have that permission.
 

Attachments

  • StartOnBootCompleted.zip
    15.6 KB · Views: 60
Upvote 0

Sergio83

Active Member
Licensed User
Longtime User
I've just compiled and ran your minial example.
I get the main page with button1, but when I click on it nothing happens!
Here after the log not filtered:
Log not filtered:
Logger connecté à :  Google X96Q
--------- beginning of main
VM with version 2.1.0 has multidex support
Installing application
VM has multidex support, MultiDex support library is disabled.
common created.
Starting remote logger. Port: 41571
EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
mapper 3.x is not supported
Arm Module v1.0
ioctl c0044901 failed with code -1: Invalid argument
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
After accept
** Activity (main) Pause event (activity is not paused). **
onActivityResult: wi is null
** Activity (main) Resume **
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
I get the screen where to set the permission for my app, and then I get the toast with Permission: True
But then the app never start on phone reboot.
 
Upvote 0

Sergio83

Active Member
Licensed User
Longtime User
It seems, like you Sagenut, that I am at a dead end.
Your minimal example doesn't work for me, and your recommendation confirmed by Erel yields no results...
So what ....
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
We have to wait for someone with more knowledge than us to show us what we are doing wrong. ;)
 
Upvote 0
Top