[Free] MyService.- Easy Foreground Service

Version 1.1

Adapted to Android's new requirements for foreground services, two new types are included:

One called Exercise, which works with any service for managing exercise, such as walking, running, cycling, etc.

Another called Message, which is valid for any chat service or other service with message content.

With these two new types, Android does not close the services dedicated to these two concepts.

Version 1.0

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

start

Starts the service

Stop

stop

Stops the service

IsServiceActive

active

Boolean indicating whether the service is active or not

BootInit

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

toback

Sends the application to the background

Location type functions and properties

latitude

longitude

altitude

accuracy

time1

time2

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 (30,4 KB) Version 1.1

es.mariosoft.MyService.aix (31,5 KB) Version 1.0

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

11 Likes

Estoy probando la extensión con un poco x6 pro android 16 y la verdad que va muy bien, manda la app a background pero sigue corriendo la ubicación, gran aporte! En kodular no funciona !

New version of the extension (see first post)

Version 1.1

Adapted to the new Android requirements for foreground services, two new types are included:

One called Exercise, which works with any service for managing exercise, such as walking, running, cycling, etc.

Another called Message, which is valid for any chat service or other services with message content.

With these two new types, Android no longer closes the services dedicated to these two concepts.