Android Question Autostart not working on Android 10?

cooperlegend

Active Member
Licensed User
Longtime User
Up til recently (i.e. Android 9)

#StartAtBoot: True

worked fine, but testing on Android 10 I couldn't get this to work.

Any ideas?
 

cooperlegend

Active Member
Licensed User
Longtime User
This is the code in the Service "Booter"

The log shows just

05-06-2020 09:27:57 Service Started
05-06-2020 09:28:12 Auto Start is enabled

"Main" isn't started !?!?

Thanks

B4X:
#Region  Service Attributes
    #StartAtBoot: True
#End Region

Sub Process_Globals
    '--- These global variables will be declared once when the application starts.
    '--- These variables can be accessed from all modules.
 
    Private tmrStart As Timer
 
End Sub
Sub Service_Create
    '--- set timer to start app after 1 seconds
    '--- this gives time for system to init other stuff
    tmrStart.Initialize("tmrStart",15000)
End Sub

Sub Service_Start (StartingIntent As Intent)
    '--- enabled timer
    tmrStart.Enabled = True
End Sub

Private Sub Service_Destroy
End Sub


Sub tmrStart_Tick
    tmrStart.Enabled = False
    '--- if we find the file 'autoStart.dat' in the folder 'File.DirInternal'
    '--- then auto start the app.
    Dim checkFile As String = "autoStart.dat"
    If File.Exists(Common.rp.GETsafeDirDefaultExternal(""),checkFile) Then
        Common.SaveLog("Auto Start is enabled")
        StartActivity(Main)
    Else
        Common.SaveLog("Auto Start is disabled")
    End If
 
End Sub
 
Upvote 0

cooperlegend

Active Member
Licensed User
Longtime User
Further info

The "Starter" service appears to also run (hence the message "Service Started" in the log file

But "StartAtBoot" is false ?!?

B4X:
#Region  Service Attributes
    #StartAtBoot: False
    #ExcludeFromLibrary: True
#End Region

Sub Process_Globals
    Public CL As Crashlytics
    Public rec As ScreenShotterContinuous
    Private adm As ADM   
End Sub

Sub Service_Create
    Dim context As JavaObject 'depends on JavaObject
    context.InitializeContext
    CL.Initialize(context)
    rec.Initialize("rec")
    adm.Initialize("ADM")   
End Sub

Sub Service_Start (StartingIntent As Intent)
    Common.SaveLog("Service Started")
 
Upvote 0

cooperlegend

Active Member
Licensed User
Longtime User
Hi, I am still struggling to get this to work on my Android 10 device, further help would be appreciated :)

Code I am using is

RequestDrawOver Class:
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


Called from the "Booter" Service

Booter Service:
#Region  Service Attributes
    #StartAtBoot: True
#End Region

Sub Process_Globals
    '--- These global variables will be declared once when the application starts.
    '--- These variables can be accessed from all modules.

    Private tmrStart As Timer
 
End Sub

Sub Service_Create
    '--- set timer to start app after 1 seconds
    '--- this gives time for system to init other stuff
    tmrStart.Initialize("tmrStart",5000)
    Common.SaveLog("Timer Initialized")
End Sub

Sub Service_Start (StartingIntent As Intent)
    '--- enabled timer
    tmrStart.Enabled = True
    Common.SaveLog("Timer Started")
End Sub

Private Sub Service_Destroy
End Sub

Sub tmrStart_Tick
    tmrStart.Enabled = False

    Common.SaveLog("Timer Tick")
    
    Dim c As RequestDrawOverPermission 'this is the name of the class
    c.Initialize
    Common.SaveLog("Requested")
    
    Wait For (c.GetPermission) Complete (Success As Boolean)
    Common.SaveLog("Permission: " & Success)
    
    Common.SaveLog("Auto Starting")
    StartActivity(Main)
 
End Sub

Looking at my "Saved" log file I can see it gets to "Requested" and then stops...

10-06-2020 16:13:37 Service Started
10-06-2020 16:13:37 Timer Initialized
10-06-2020 16:13:37 Timer Started
10-06-2020 16:13:42 Timer Tick
10-06-2020 16:13:42 Requested


Weirdly it also show "Service Started" from the "Starter" service which is set to "#StartAtBoot: False" !!!
 
Upvote 0

cooperlegend

Active Member
Licensed User
Longtime User
So I copied this part to my Main Activity

B4X:
    Dim c As RequestDrawOverPermission 'this is the name of the class
    c.Initialize
    Common.SaveLog("Requested")
    
    Wait For (c.GetPermission) Complete (Success As Boolean)
    Common.SaveLog("Permission: " & Success)

Then traced it in Debug and it got to the bottom of the sub "StartActivityForResult(i As Intent)" and then just stopped.

I just don't get this, please can you explain in more detail, thanks
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is what I see when I run your program on an Android 10 device:


1591942075733.png


And the logs:

Copying updated assets files (1)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Requested
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
** Activity (main) Resume **
Permission: true
 
Upvote 0

cooperlegend

Active Member
Licensed User
Longtime User
I don't get the "Allow Display" message when I run this test App on my Tanix Android TV box :(
It also doesn't run when re-booted.

Android 9 was perfect, this and the streaming screenshot message problem seem to have made Android 10 a non starter for me...

Any ideas?
 
Upvote 0

cooperlegend

Active Member
Licensed User
Longtime User
Is there any way to force this permission?

As I said, on my Android TV Box this permission is not being requested on the screen with the test program I sent

Thanks
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Is there any way to force this permission?
To Install Unknown Apps
Settings -> Passwords & security -> Privacy -> Special app access -> B4A-Bridge -> Install unknown apps

To Draw over Apps
Settings -> Passwords & security -> Privacy -> Special app access -> B4A-Bridge -> Display over other apps

To install when B4A-Bridge is not in the foreground
Settings -> Apps -> Permissions -> Other Permissions -> B4A-Bridge -> Display pop-up windows while running in the background
 
Upvote 0

cooperlegend

Active Member
Licensed User
Longtime User
I could get to the permissions screen for my App, where is just says "No permissions" , how do I add "Display over other Apps" permission to the box ?
 
Upvote 0

cooperlegend

Active Member
Licensed User
Longtime User
I did some more searching and found the setting for my test App, but not for my "real" App, I think I am on the right track now, just need to check the code in my "real" app and make sure it is right.

Thank you :)
 
Upvote 0
Top