Android realizes the function of simple pedometer, clears the steps every other day, and views the historical motion record

Recently, I need to use the step counting function, which is difficult for me. The IOS terminal is good and has its own step counting function. To my surprise, I have even finished climbing the floor. I only need to adjust the interface to obtain data. I have an MMP, which I want to talk about very much.

However, complaints are complaints, and the functions still have to be realized in advance. Wechat sports and Le power are all good. In particular, Le power's step counting function is really powerful. In the UI domain, user interaction is also very good. The party needs to start step counting after ten consecutive steps. I wanted to find the algorithm they implemented and use it, but it was obviously impossible. Later, I searched a lot of data and found that the new step detector and step counter sensors in Android 4.4 KitKat. But! Although the Android sensor can count steps, the number of steps recorded is calculated from the time you start the machine. It is accumulated continuously and will not be cleared the next day. Moreover, once the machine is turned off, the data recorded by the sensor will be cleared! This is very embarrassing, but since it is not possible to directly use the sensor data, let's do it ourselves and save the data by day ~ next, let's get to the point, Pippi ape, let's go~

Let's first look at the points we need to solve:

1. The number of steps is accumulated continuously after startup, and is cleared after shutdown. The number of steps cannot be cleared the next day

2. Historical data cannot be viewed

That's easy. We only need to save the steps recorded by the current sensor into the database every day. If the updated steps are the steps of the day, update the database! Let's take a look at my interface first (the demo is at the end of the article):

The first and second pictures are the interface renderings. The data is taken from the data and drawn on the interface. The third picture is the notification style set when setting the foreground process. Of course, this style can be customized. I won't explain it in detail.

The directory structure of the project is as follows:

The main codes are in stepservice.class, and the comments are very detailed. I'll put the code directly:

There is also a lot to learn about the service, one of the four major components, which has been mended in recent days. It can be regarded as making up for the regret of not studying carefully in school --

The main thing to say is the above. The source code is here. Click me

The above is what Xiaobian introduced to you. Android realizes the simple pedometer function. The next day, the number of steps is cleared to check the historical sports records. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>