Excuse my english I use google translator
Version 2 is attached that solves a Bug for which the time did not reset properly when the ResetDaily is active
es.mariosoft.AcePedometer.aix (50.0 KB) (v2)
This extension is a continuation of my first [FREE] Pedometer Sensor (not accelerometer) extension, it is a full-featured pedometer for creating a fitness app, which includes a foreground service with its corresponding notification.
First of all, we are going to define what a service is in android, especially since sdk 8, the service allows the application to continue counting steps despite being closed, but android one of its main tasks is to avoid excessive battery consumption so it kills services when memory usage is compromised.
To avoid this we must create a service that consumes the minimum of memory and that the bulk of the calculations is done by the activity, therefore the service only performs the following functions:
- Count steps
- It counts the elapsed time (the real one, that is, it only counts the time when we are walking, not in a continuous way)
- Creates a daily database with the steps taken and the time if the user uses ResetDaily.
- Respond to the requests of the activity to reset the steps and time.
The rest is done by the activity.
In addition, the user must allow the AutoInit of the service and the use of the battery without restrictions (the battery consumption by the service is minimal)
for this there are these two blocks:
This does not lead to the AutoInit configuration
and this will take us to a page where it explains depending on the brand of the device how to use the battery without restrictions
If all these concepts are configured correctly the service will count steps indefinitely if you do not stop the service
The pedometer
The extension allows the use of two types of sensors to count the steps: the accelerometer or the Sensor Detector of steps that some devices carry.
for this we can use these blocks
Another feature of the extension is that it uses a WAKE_LOCK to prevent the activity from entering Doze mode when it has not been closed, this would allow us if the application is not closed for example, that the app warns us every time we perform 1000 steps, although is asleep, to avoid closing the application the extension has the following block that mimics the Home button of the device.
As we already mentioned, the service calculates the steps and the time and the activity is in charge of calculating the distance (km or miles), the calories consumed, the speed (Km / h or Miles / h). for this we use these blocks
For this, the user must supply the following data: stride length, weight and daily goal.
for this we use these blocks
To handle the database we will use these blocks
All data (database, step length, weight, goal …) are permanently saved in the app when we change it, being available at the next start of the app
the app will not work in the companion for it to work you must compile it
Two other features of the application is that it allows you to create a daily base of the steps through ResetDaily
And whether or not to allow the service notification to open the activity when we click on the aforementioned notification
I would like to thank Ullis Robert Seite Ullis Roboter Seite/AI2 Keep Alive
for its source of service that served as the basis for mine.
In kodular at the moment it does not write the service correctly in the manifest, so I provide an extension of the ATOM developer master that solves this problem
es.mariosoft.AcePedometer.aix (49.8 KB)
AceStepsko.aia (61.3 KB)
com.atomdeveloper.ManifestCode.aix (6.1 KB)