Develop an Alarm Feature for Wearable App in Harmony OS

Ece Aydın
Huawei Developers
Published in
3 min readDec 30, 2021

Hello everyone,

In this article, I will introduce you to the Harmony OS operating system that Huawei has recently offered to developers, and I will explain how we can create a simple-scale alarm application with this operating system on the wearable side.

What is Harmony OS?

Harmony OS is a next-generation operating system that strengthens interconnection and collaboration between smart devices.

Harmony OS, which Huawei aims to manage all smart objects with a single operating system, can run on all devices with processors such as cars, smartphones, smartwatches, computers, smart home systems, and televisions. With its micro-core-based development, it focuses on internet of things technology and enables all devices on which the operating system is installed to communicate with each other.

Creating the Project

In this article, we will develop a snooze (alarm) application to be used on Huawei wearable devices to set an example for you. We use DevEco Studio to develop with Harmony OS. We can also use a Wearable watch or simulator to test our app.

You can follow the steps below to create our Wearable project on DevEco Studio.

  1. Follow the File > New >New Project path.

2. On the opened page, choose the Empty Ability template and click the Next button. Wearable projects, unlike Lite Wearable projects, allow development with Java as well as JS.

3. On the page that opens, the necessary information about the project is filled and the project type and device information are selected. The project is created by clicking the Finish button.

Project Development

Our project consists of three basic units. These are the .js file where the main functions are specified, and the .css and .html files where the UI design of the page is shaped.

We have four buttons from which we can choose how many minutes we want to delay our recall.

alarm.html

alarm.css

alarm.js

We make use of the setTimeout() method for each time period in which we set our alarm.

After selecting the delay time, we give a toast message to the screen by using the showToast() method to indicate to the user how many minutes to delay.

Finally, when the selected delay time expires, the user is warned with the vibration feature. For this, we use the vibrate() method in ‘long’ mode. In this way, the clock vibrates for a long time.

Conclusion

  • Before using the vibrate feature, make sure you have the necessary permissions in the project’s config.json file.
  • For Java projects that support API 6 and above, you can develop your project more easily by using ReminderManager.

References

--

--