Health Kit | Data Controller Sample

Efnan Akkuş
Huawei Developers
Published in
4 min readOct 7, 2020

Hello everyone, in this article, we’ll develop an android application using the Huawei Health kit’s data controller feature. Lets get start it.

About the Service

HUAWEI Health Kit (Health Kit for short) 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.

Health Kit is open to enterprise developers and individual developers.

Configure your project on AppGallery Connect

Registering a Huawei ID

You need to register a Huawei ID to use the plugin. If you don’t have one, follow the instructions here.

Preparations for Integrating HUAWEI HMS Core

First of all, you need to integrate Huawei Mobile Services with your application. I will not get into details about how to integrate your application but you can use this tutorial as step by step guide.

Add required dependency to the app-level build.gradle file.

Lets add the required permissions to the AndroidManifest.xml file.

Applying for Health Kit

You should select the data access permissions that must be applied for the product.

For more detail you should visit: https://developer.huawei.com/consumer/en/doc/apply-kitservice-0000001050071707-V5

Developing Your App

Signing In and Applying for Scopes

The developer’s app calls the related APIs to display HUAWEI ID sign-in screen and authorization screen. The app can only access data upon user authorization. The user can select the data types to be authorized and grant only some data permissions.

For details about the sign-in process, please refer to HUAWEI Account Kit Development Guide.

DataController

After integrating Health Kit, the app is able to call ten methods in DataController to perform operations on the fitness and health data. The methods include:

  • insert: inserts data.
  • delete: deletes data.
  • update: updates data.
  • read: reads data.
  • readTodaySummation: queries the statistical data of the current day.
  • readDailySummation: queries the statistical data of multiple days.
  • clearAll: clears data of the app from the device and cloud.

Inserting the User’s Fitness and Health Data

Insert the user’s fitness and health data into the Health platform.

Deleting the User’s Fitness and Health Data

Only historical data that has been inserted by the current app can be deleted from the Health platform.

Updating the User’s Fitness and Health Data

Querying the User’s Fitness and Health Data

To read historical data from the Health platform, for example, to read the number of steps taken within a period of time, you can specify the read conditions in ReadOptions. For example, you can specify the data collector, data type, and detailed data. The dataset that matches the query criteria will be returned.

Querying the Statistical Fitness and Health Data of the User of the Day

Querying the Statistical Fitness and Health Data of the User of Multiple Days

Clearing the User’s Fitness and Health Data from the Device and Cloud

Call the clearAll method of the DataController to delete data inserted by the current app from the device and cloud

We successfully integrated Huawei Health Kit’s Data Controller feature into our project. Here’s the result.

--

--