👨🏼‍💻Wear OS Development Notes

Eren ÇOLAK
Huawei Developers
Published in
5 min readApr 7, 2022

--

Image Resource

Introduction

We will introduce wear os development. In this article, we will try to explain how you can start development. You must know the below before starting development.

General UI

- A round screen has %22 less UI space than a rectangular display.

- Make sure your app is working on rectangular and round displays.

- Wear OS designed to be used on the move

- Work with activities, not advising to use fragments.

- A UI design that works well on a computer monitor may not work in real life on a watch

- Test your design one wear OS device

- We can separate the dimensions for round and not round displays

- Some Wear OS Specific UI Objects.

Wear OS Operating System Features

- Wear OS supports always-on apps that have longer user sessions.

- When the user is not using your app, Wear OS dismisses it and returns the watch face.

- With Always-On apps, when the user is not using your app, the watch will go into ambient mode. Turn off the processor, but keep your app in the foreground.

- While your app is in ambient mode, you can update it once a minute, providing useful updates

- Adding Ambient mode support

- Former is when your app is a full-fledged app on your watch and does not need a supportive app on the Phone, an example can be the weather app.

- Latter is when you need your other app to run on the phone, an example can be the smart lights app where all heavy lifting is done on phone, and the watch app is just to send commands. Below is a screenshot of the companion watch app for smart lights.

- Wear OS can supply data from Google or other third-party apps to your watch face.

- Developers can choose to implement a complication data provider, which allows the app to share data with the watch face.

- To get started, create a complication provider service, and supply the data requested on demand.

- You can also ask the system to request an update when new information becomes available, such as a new chat message, or a piece of breaking news.

- To conserve battery, Wear OS may reduce the update frequency. Complication update intervals are on the order of minutes rather than seconds.

- Notification preview complication is important.

- Recently launched app complication.

- With Android P, battery capacity increased by %10

- Can creates jobs and alarms

- On the battery saver mode; radio, touch, and tilt detections are closing.

Connection With Main App

- Android calls all these devices as nodes.

- Android came up with a decent solution. Instead of you querying all nodes(devices) and finding which has your app installed. Wear API offers a utility to do so.

Wearable.getCapabilityClient(context)
.getCapability(“Capability String You define, CapabilityClient.FILTER_REACHABLE);

- It means you can expose a string literal which acts as a unique identifier when wear API will find your app in nodes mesh.

- Simplifying more, your app module on different devices can expose some offerings(capability in Android wear term) for e.g. Your phone app module can say I am “watch-server” and watch module can say I am “watch-client”.

- You can use the same API on both devices, watches, and phones. All you need to do is use different capability

//In Watch

Wearable.getCapabilityClient(context)
.getCapability(Constants.CAPABILITY_PHONE_APP, CapabilityClient.FILTER_REACHABLE);
capabilityInfoTask.addOnCompleteListener(…

// In Phone

Task<CapabilityInfo> capabilityInfoTask = Wearable.getCapabilityClient(context)
.getCapability(CAPABILITY_WATCH_APP, CapabilityClient.FILTER_REACHABLE);
capabilityInfoTask.addOnCompleteListener(…

Data Strategy for Wear OS

- Wear OS supports multiple wearables connected to a handheld device. For example, when the user saves a note on a handheld, it automatically appears on all of the user’s Wear OS devices.

- To help synchronize data between devices, Google’s servers host a cloud node in the network of devices.

- The system synchronizes data to directly connected devices, the cloud node, and wearable devices connected to the cloud node using wifi

- The following table shows the different requirements and use cases for each client.

- A data client exposes an API for components to read or write to a DataItem or Asset

- The ChannelClient can transfer data from a handheld to a wearable device, with ChannelClient you can do the following things;

- The MessageClient can send messages and it is good for remote procedure calls(RPC), such as controlling a handheld media player from the wearable or starting an intent on the wearable from the handheld.

Listen for Important Data Layer Events

- For Services; Extending WearableListenerService lets you listen for important data layer events in service. The system manages the lifecycle of the WearableListenerService, binding to the service when it needs to send data items or messages, and unbinding the service when no work is needed.

- For Foreground Activities; Implementing OnDataChangedListener in an activity lets you listen for important data layer events when an activity is in the foreground. Using this instead of the WearableListenerService lets you listen for changes only when the user is actively using your app.

Watch Face

- Watch face is changing with battery optimized watch face on battery saving mode

- By overriding the onDraw method in the canvas watch face service, you can draw lines, shapes, or render bitmaps.

- Before android P dark mode has #232E33 color. After it has #000000 (This reduces power consumption)

- Wear OS supports development with Jetpack Compose

Thanks for your support my teammate in HUAWEI Enes Erkoç

Resources

Wearable Data Layer

Understanding_the_Characteristics_of_Android_Wear_Os

--

--