Hello,
I have simple task but can't accomlish it.
I have H96 Android box and write small B4A app that must start automaticly when android box lose his power - restart.
I try to set my app as launcher - not work!
Now i try add receiver and get android.intent.action.BOOT_COMPLETED, then start Main activity - not work!
This is my simple project. Can someone help me with this?
I read that Android boxes have a setting that allows them to start apps on restart, but I can't find one.
This is my code:
Also i have this lines into manifest:
I have simple task but can't accomlish it.
I have H96 Android box and write small B4A app that must start automaticly when android box lose his power - restart.
I try to set my app as launcher - not work!
Now i try add receiver and get android.intent.action.BOOT_COMPLETED, then start Main activity - not work!
This is my simple project. Can someone help me with this?
I read that Android boxes have a setting that allows them to start apps on restart, but I can't find one.
This is my code:
Starter.bas:
#Region Service Attributes
#StartAtBoot: False
#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.
Log("BootService started")
StartActivity(Main)
StopService("")
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
MyRecever.bas:
Sub Process_Globals
End Sub
'Called when an intent is received.
'Do not assume that anything else, including the starter service, has run before this method.
Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
' Стартираме Main Activity при BOOT_COMPLETED
If StartingIntent.IsInitialized Then
If StartingIntent.Action = "android.intent.action.BOOT_COMPLETED" Then
Log("BOOT_COMPLETED received -> starting Main Activity")
StartService(Starter)
Else
Log(StartingIntent & " -> detected")
End If
End If
End Sub
Also i have this lines into manifest:
Manifest:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="35"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
'End of default text.
AddPermission(android.permission.RECEIVE_BOOT_COMPLETED)
AddReceiverText(MyReceiver, <intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>)
B4X:
Attachments
Last edited: