An extension that provides a Foreground service.
Designed for all types of users, preferably beginners due to its ease of use.
Unlike other large extensions that provide a service and rely on the service being run internally, with complicated configurations within our AIA,
this extension's internal job is only to keep the application alive, being very persistent and difficult to close.
This makes creating an application as simple as creating a normal application, using the App Inventor components and including the service. This will keep our application running as long as we don't close the service.
The service works in all application lifecycles, meaning the application can be in the foreground or background, minimized...
If Android close our service, we accidentally close it, or we restart the phone, the service will always revive and start the app running. To do this, it is necessary to configure the application to restart in the background. The extension allows us to use the dialog to do this.
The extension does not require DozeMode to function, but it may be necessary to activate it in some cases. I have included a separate extension to configure DozeMode.
There are two types of services: General and Location. Why is there a specific one for Location?
Activating BackgroundLocation requires a special reference within the androidmanifest file and requires the sensor listener to be directed from within the service. Therefore, this type works differently than the General type.
When we create an app, we only need to request the user to configure the bootinit.
We don't need to ask the user for any other permissions, except for the Location type, where we need to request the user for location permissions.
It is necessary to indicate in our applications that each time it is initialized, it should restart the service.
It is important to emphasize that, like any other service, these drain batteries, so it is best to use them only when necessary, especially in the Location type.
Despite this, in the AIA example with a pedometer, the service always works and battery consumption is around 5%.
Below are the extension's properties and functions:
Property Designer
ChannelName
Notification channel name
NotificationIconAsset
Notification icon in the Asset
NotificationId
Integer with the notification number
ServiceType
Service type (Location or General)
Functions
Start
Starts the service
Stop
Stops the service
IsServiceActive
Boolean indicating whether the service is active or not
BootInit
Dialog to allow the service to start when the service is restarted or destroyed
NotificationTitleText
Allows you to specify a title and text for the real-time service notification
ToBackground
Sends the application to the background
Location type functions and properties
Examples
Pedometer with the AppInventor component
MIWalks.aia (70,2 KB)
Pedometer with the MyPedometer extension
MyWalks.aia (79,8 KB)
AppInventor web monitoring extensions every 10 minutes
MiWeb.aia (79,0 KB)
Example of Location indicating Data on the distance traveled and indicating the different positions on a map
MyLocation.aia (52,9 KB)
Extensions
es.mariosoft.MyService.aix (31,5 KB)
es.mariosoft.dozemode.aix (5,8 KB)
es.mariosoft.mypedometer.aix (9,2 KB)
Important
The application will only work when compiled; it does not work in the companion application.
Un saludo