Read Daily Step Data with Health Kit

Çağnur Hacımahmutoğlu Parçal
Huawei Developers
Published in
4 min readDec 25, 2020

--

Happy Walk :)

Hello everyone,

Especially recently when we realized how important the “health” issue is for us, we learned how important it is to act in order to lead a healthy life. For the days when we worked in the home office and forgot to act like as a human, we can follow our daily steps, how many steps we have taken in 3 months and how many calories we have burned. We develop sample app to use this properties. We used these features with the help of Health Kit.

Before step into development progress, let’s examine what is Huawei Health Kit and what are the main functions.

Huawei Health Kit :

HUAWEI Health Kit allows ecosystem apps to access fitness and health data of users based on their HUAWEI ID and authorization. For consumers, Health Kit provides a mechanism for fitness and health data storage and sharing based on flexible authorization. For developers and partners, Health Kit provides a data platform and fitness and health open capabilities, so that they can build related apps and services based on a multitude of data types. Health Kit connects the hardware devices and ecosystem apps to provide consumers with health care, workout guidance, and ultimate service experience.

Main Functions :

· Data storage

Provides a data platform for developers to store fitness and health data.

· Data openness

Provides a wide range of fitness and health APIs and supports sharing of the various fitness and health data, including step count, weight, and heart rate.

· Data access authorization management

Provides settings for users and developers so users can manage developers’ access to their health and fitness data, guaranteeing users’ data privacy and legal rights.

· Device access

Provides hardware devices (including fitness and health devices) with APIs for measuring and uploading data through the standard Bluetooth protocol.

You can browse this page to examine it in more detail.

Development Process

We learned about Huawei Health Kit and its main functions. Now, we can move on development part. Primarily, we should create a project on App Gallery Connect. You can follow the steps from the link below.

After all these steps, we need to apply for Health Kit.

Health Kit

Then, we need to select data and their permissions.

Permissions

!!! To access health data we need to authenticate the user with Huawei ID.

Let’s continue by coding Data Controller to get our users’ step data.

After creating the Data Controller, we write the read Daily function to get daily steps data of our users.

Let’s build the request body for reading activity records for readOptions method. We call the read method of the Data Controller to obtain activity records from the Health platform based on the conditions in the request body. Also, we should set time format. The daily hours reading format should be like this:

” yyyy-MM-dd hh: mm: ss “

Bonus : I used pagination to displaying step data for better user experience and resource management

Finally, we completed our development process. Let’s see how it looks in our project. :)

Conclusion

We have created an application where we can track our daily step count by taking advantage of the features provided by the Health Kit. I think it is necessary for all of us to face this reality. I hope it has been useful article for you. Your questions and opinions are very important to me.

See you in the next article…

Done ! :)

References :

--

--