Wear OS, previously called Android Wear, is a version of Google’s Android operating system designed for smartwatches. There are millions of devices currently using Wear OS and I believe this is only going to increase. In this blog post you will understand everything that you need to know to publish a watch face in Wear OS.
When you create a new Android project and select the Wear option, Android Studio will provide you with all the code that you need to create a watch face, you just need to understand it. So let’s get started!
The AndroidManifest.xml
file is almost the same as you will see in any other app. At the top you will notice two permissions.
The first permission is required by all watch faces and the second permission is required only if you are displaying some data in the watch face through a complication
.
This is another important tag that needs to be declared in the manifest. This is the only way to identify a Wear OS app from an Android app.
Watch faces in Wear OS are implemented as services. So we need to register our watch face service in the manifest.
Let’s dive into the code and start exploring the MyWatchFace.kt
file.
We are initialising all our variables in the onCreate
. We are initialising our variables only once when our WatchFace service is created and then we are re using them, this helps us to improve battery life. Battery life of smartwatches is usually only 1/10th of a smart phone, so it is important that we take necessary steps to improve the battery life.
The Wear OS devices will switch between two modes, ie Ambient
mode and the Interactive
mode. In the Ambient mode, the device will be running on low power mode whereas in the Interactive, the user can actively use the device.
You can access the onAmbientModeChanged
method to adjust the style of the watch face according to the mode.
onSurfaceChanged
is where all the graphical computations should happen. This is the first time we have access to the device’s height and width. It is a good practice to use these measurements for our calculations instead of using hardcoded values. We can use it to calculate the centre of the watch face, height of hour and minute hands etc. We should also create our Bitmap here.
Now we will understand how to implement the onDraw
method. This method provides us with a canvas
which we can use to draw our background bitmap and the watch hands. We will also calculate when the hands of the clock should be rotated here.
The users of your watch face can be travelling from one timezone to another. We need to handle this case too. We need to create a BroadcastReceiver
to check if the timezone of the user has changed. We can check the timezone in the onVisibilityChanged
method. This method tells whether our watch face is visible or not. We can check if the timezone has changed while our watch face wasn’t visible.
This is pretty much all that you need to know about the Wear OS ecosystem to build your own watch face. The project from where all the above code snippets are, is linked below. Feel free to fork and create your own watch faces with it.
Contribute to nikit19/WatchFace development by creating an account on GitHub.
github.com
There are few things that I would like to highlight about Wear OS:
- You have the option creating a watch face with Kotlin or Java and I know we all love Kotlin but the size of the apk will increase if you chose Kotlin. In my experience the size of the apk was around 600 KB more when I made a project in Kotlin. Smart watches have limited storage so we should try our best to keep the project size as small as possible.
- All Wear OS apps are reviewed after you publish them. So even after publishing the app in the PlayStore, it won’t be available unless it gets approved. So it usually takes a few days before the watch face is approved and becomes available to all the users.
- If you set the
minSdkVersion
to 25, your watch face will only be available to devices running Wear OS 2.0 or higher. If you want your watch face to be available to all the Wear OS devices set theminSdkVersion
to 23. - In Wear 1.x, watch apps were distributed by embedding it inside a phone app but now Wear OS allows us to distribute standalone Wear apps in the same way for both Wear 1.0 and 2.0.
- Wear OS devices will not always have a circular screen. It may be square shaped also. So… you have to handle that case also. It’s a good practice to create 2 dimensions, one for circular devices and the other for square devices.
- The process of publishing a watch face in PlayStore is exactly the same as publishing an app, you just have to specify that it is an app for the Wear OS platform.
I have linked below a few watch faces made by me feel free to check them out!
Digital Watch Face - Apps on Google Play
Features: Support both round and square watch Support ambient mode More customisation options will be added in future…
play.google.com
Analog Watch Face - Apps on Google Play