This repository hosts a basic sample code for HarmonyOS Lite Wearables. The app allows users to monitor their heart rate (HR) and see its evolution on a graph.
The example is implemented as a unique page based on feature abilities (FA) using JavaScript APIs.
Compatible with HarmonyOS SDK 2.2.0 (API 6), and supports SDK 3.0.0 (API 7).
In the code, you can check the controls for conditional rendering and state properties binding (i.e., in pages/index/index.hml
):
<div class="reading-animation" if="{{readingHR}}" >
<image-animator class="heart" ref="animator" images="{{heartFrames}}" duration="0.4s" />
<text class="hr" >{{hr}}</text>
</div>
In the logic of the app (i.e., pages/index/index.js
), you can check how to subscribe to sensor changes, like the HR and on-body sensors:
sensor.subscribeHeartRate({
success: function(ret) {
// Every time a change is detected, updates the buffer and chart
console.debug(`Got HR value: ${ret.heartRate}`);
},
fail: function(data, code) {
console.error(`[subscribeHR()] Subscription failed. Code = ${code}, Data = ${data}`);
},
});
Also some functions that use the local device filesystem (i.e., write, list, and read files).
In the /config.json
file, you can find how to declare permissions to use powerful features.
- Clone this repository to access the code locally.
- Download the latest version of the DevEco Studio IDE.
- Load the project in the IDE and get the dependencies.
- Test it on the built-in Huawei Lite Wearable Simulator (in the IDE).
- Test the app on a real device (see this blog post for more info)
You can improve the code as you wish. Have a look at the official development documentation for lite wearables.