Android Question How I can launch automatically my an app when mobile is startup ?

Alhootti

Active Member
Good Evening Guys

need to launch my app when i switch on my mobile, on another hand it launch automatically when my mobile get starting
 

Alhootti

Active Member
Erel
I Followed the instructions but my app is not working in boot of mobile

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

Starter:
#Region  Service Attributes
    #StartAtBoot: True
    #ExcludeFromLibrary: 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.

End Sub

Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.

End Sub

Sub Service_Start (StartingIntent As Intent)
    Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
End Sub

Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
End Sub

'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub Service_Destroy

End Sub

app:
#Region  Project Attributes
    #ApplicationLabel: Startup Tester
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: 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 xui As XUI
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

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

manifest:
AddPermission(android.permission.SYSTEM_ALERT_WINDOW)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I Followed the instructions but my app is not working in boot of mobile
i don´t see you have added a NEW Service which runs at boot. You should NOT set startatboot to the starter-service!

The starter service should never be explicitly started. This means that if you want to start a service at boot then add a different service.
 
Last edited:
Upvote 1
Top