Huawei Health Kit Activity Record: Cycling

Introduction

Feyza Ürkut
Huawei Developers
4 min readJan 4, 2023

--

Hello, everyone🙌 In this article, I will show you how we can record activities using the example of cycling with Huawei Health Kit. I will also talk about how to decide on permissions and data types in Huawei Health Kit. Let’s start!

Photo by Viktor Bystrov on Unsplash

Huawei Health Kit

With Huawei Health Kit, ecosystem apps can access the activity and health data of users based on their HUAWEI ID and authorization. Health Kit allows consumers to store and share their activity and health data storage with flexible authorization options. Developers and partners can build related apps and services based on a variety of data types, thanks to Health Kit’s data platform and open capabilities.

First of all, you can follow the development process to prepare for integration and development.

How to Decide Necessary Permissions and Data Types?

  • Before obtaining the permissions, we find and review the type of activity we will use from the Data Types section of the official Huawei Developers site. We need to pay close attention to the data types of the related activity.
Reference Link
  • In this section, when deciding on permissions, we need to get the permissions of the mandatory ones from the Associated Sampling Statistical Data Types. Apart from the mandatory ones, if we have to use them in our application, we need to get their permission as well.
Reference Link
  • By looking at the Associated Atomic Sampling Data Types, decide the data collector type for detailed data. In this example, we use DataType.DT_INSTANTANEOUS_PEDALING_RATE.
Reference Link

Sign In with Huawei ID

User authorization is required on the HUAWEI ID sign-in and authorization screens for your app to access data. Users can select the data types to be authorized and grant only some data scopes. The data that your app can access is both approved by Health Kit and granted by users.

We just need to add some scopes to use the Health Kit. Below are shown those that are for our example. The scopes may vary depending on your specific needs or different types of activities.

Writing Cycling Record to Health Kit

Health Kit doesn’t do calculations. For example, if you don’t write calories, the Health Kit doesn’t automatically count calories.

1- Create an ActivityRecordsController object to write activity records to Health Kit.

2- Create DataCollector objects to handle user data.

3- In the repository class, we can call the related DataCollector object via “@Named” annotation.

4- Create SamplePoint objects

We start our operations by giving our addActivityRecord() method all the necessary parameters for the activity record that we obtained in our application.

Build sampling points for statistical data based on the data collector and add the sampling points to the DataSummary object.

5- Create an ActivityRecord object by specifying a time period and other necessary information.

We must be careful to provide unique IDs for each activity record or the records will not be created. We used HiHealthActivities.CYCLING for the activity type id in this example.

6- Create an ActivityRecordInsertOptions object using ActivityRecord and available datasets or aggregate sampling point data.

7- Insert ActivityRecordInsertOptions using ActivityRecordsController.addActivityRecord().

This method inserts activity records and corresponding data into the Huawei Health kit, including activity record details and sample data sets.

Conclusion

In this article, I tried to explain how we should review the official documents and decide on the necessary permissions and data types before starting the developments with the Health Kit. In the sequel, I talked about how we can perform an activity recording based on the example of cycling. If you want to get more detailed information about the Health Kit, you can take a look at the References section.

Pleasant work for everyone 😊

--

--