[FREE] Pedometer with Foreground Service (V2)

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

bootinit

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

urlhelp

If all these concepts are configured correctly the service will count steps indefinitely if you do not stop the service

start stop reset isactive

The pedometer
Properties
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

sensortipe issensor setsensor

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.

homekey

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

eventWalkStep calories distance formattime getsteps gettimes kmtomille speeed

For this, the user must supply the following data: stride length, weight and daily goal.
for this we use these blocks

setgoal setlen setpeso

To handle the database we will use these blocks

getdata getdistance getcalories getstep gettime

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

setdaily

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)

19 Likes

great work thanks for that!!!

Good work.helpful extension.keep building :slightly_smiling_face:

Hey,
Is there a tutorial for this extension describing and showing what each block is doing cause some of those I still can’t understand, and how do I make it change text by one when it detects a step + it is always running, you don’t have to click start or anything?

That’s exactly what I needed :heart_eyes: :heart_eyes: :heart_eyes:

May Bless u for your Contribution

2 Likes

Great Extension . Thanks for it .

I do not know exactly what your problem is but I am going to describe the reasons why it does not tell you steps
All the captures are taken from the .aia file of the first message, I recommend that you download it.
Indeed you have to tell the service to start, we can do it in two ways

It may also happen that you want to use the Hardware Sensor and your device does not have it, this can be solved with the following function

Another reason is that you have not included the atom extension in your Project to write the manifest. I accompany it again

extension removed by Mod - you can not post direct an extension unless you are the developer

If you download the .aia file from the first message, it will clarify how the extension works, especially in the use of the database, which is somewhat more complex

Shortly a new version of the extension will be published that solves a bug that exists when we reset daily, since sometimes it does not reset the time well

Hi,
It is a great extension. I have used it for a while and I think it is the best free pedometer extension.
However lately I discovered that if I change the package name of my application, this extension cause problem. I created a new project to show this easily. I only added ManifestCode and AcePedometer to the screen, set a custom package name and added AcePedometer.Start block when screen initializes. It causes the error “app keeps stopping”. I added screenshots of everything I explained here below.

How can I fix this problem?

blocks

Indeed, when you change the name of the package in Kodular, it gives this error.
It is a problem of how to link, kodulate the names of the packages since android cannot find the service and stops
I will investigate how to solve this problem, I also ask for help in case someone knows a solution

All the best

1 Like