How to develop a Heart rate reader application

Asharali V U
4 min readJan 18, 2021

--

Introduction

In this article, will explain how to develop heart reading health application integration on Harmony lite wearable. Following are the APIs we are going to integrate with this application.

1) On Body status API: To detect the watch is tied with the user’s wrist.

2) Heart rate API: To read the heart rate.

3) Memory storage API: To cache the previous reading.

4) Keep screen on API: To keep the screen on for 5 minutes.

Moving to this article if you are new to the Harmony platform, you can check this article: Huawei Lite Wearable Application Development using HUAWEI DevEco Studio (HamonyOS)

Requirements

1) DevEco IDE

2) Lite wearable watch (Can use simulator also)

Steps to create the project

1) Open the DevEco studio, choose File > New > New Project to create the new project.

2) Select the Lite Wearable project and select Template.

3) Enter the Project Name and Package name, and then click Finish.

Flow chart

Here is the flow chart of the application that we are going to integrate.

Integration process

Step 1: Design the UI

As the first step, we can create a UI that contains two texts, one for the heading and another for showing the result.

index.html

index.css

Run the application, and you can see an output as given below.

Step 2: Integrate On Body State API

Now we will move to the API part. Firstly we have to add code to check if the user is tied with the watch or not. For that, we have on body state API.

Step 3: Heart Rate API integration

If the on body state is true then we are calling the heart rate API function.

We need to add permissions on the app.js to run this API on the real watch. So add the below permission on the module section of the app.js file

Add two data items, one item to update the UI and the next one to do the caching.

Step 4: Storage Write API integration

Once you get the value, it’s time to save your heart rate on the device. To save the data you have to use the following API.

It’s important to unsubscribe the services on Body State API and Heart Rate API after use. So add the unsubscribe function on destroy.

Step 5: Storage Read API integration

Now it’s time to retrieve the previously stored data on the launch of the application. Use the below snippet for it.

Step 6: Keep Screen On API integration

So now we are ready to run the application. We can run the application and see the output. If you want to show the screen for more than 30 seconds, you can use the below code and enable a long time display.

The final code for your application will be as given below.

Results

Tips & Tricks

· Don’t add package name which is having more than 30 characters. Right now only 30 characters are accepted on the Lite wearable

· Make sure you are added the heart rate permission. If you are not added the permission application will work fine on the simulator, but not on the real device.

Conclusion

In this article, we are learned how to implement a fully functional heart rating application. We have also learned other API integrations like On Body State, Keep screen on, and Storage.

Reference

· Harmony Official document — https://developer.harmonyos.com/en/docs/documentation/doc-guides/harmonyos-overview-0000000000011903

· DevEco Studio User guide — https://developer.harmonyos.com/en/docs/documentation/doc-guides/tools_overview-0000001053582387

· JS API Reference — https://developer.harmonyos.com/en/docs/documentation/doc-references/js-apis-overview-0000001056361791

--

--

Asharali V U
Asharali V U

No responses yet