Skip to content

Latest commit

 

History

History

README.md

Wear Widget Sample

Demonstrates building Wear Widgets using Remote Compose for Wear OS.

Introduction

Wear Widgets are partial-height, vertically scrolling surfaces that complement apps and watch faces, providing effortless access to information and key actions. They leverage Remote Compose, featuring a declarative DSL similar to Jetpack Compose.

This sample includes:

  • HelloWidget: A simple "Hello World" widget.
  • WeatherWidget: A widget that displays dynamic content based on stored state.

Compatibility

Wear Widgets are compatible with Wear OS 4 and above. On devices where native widgets are not supported, the library automatically translates them and makes them available to the system as a Tile.

Getting Started

This sample uses the Gradle build system. To build this project, use the ./gradlew build command or import it into Android Studio.

Build and Install

./gradlew :app:installDebug

Add and Preview your Widget

To test how your widget translates to a full-screen Tile on older Wear OS versions, you can inject it directly into the system carousel using ADB.

1. Add the tile:

adb shell am broadcast \
  -a com.google.android.wearable.app.DEBUG_SURFACE \
  --es operation add-tile \
  --ecn component com.google.example.wear_widget/.HelloWidgetService

Note: The preceding command adds a FULLSCREEN tile by default. You can also specify LARGE and SMALL sizes by passing --ei type [0|1|2] to the command (where type 0 is FULLSCREEN). Depending on the device state, app-triggered content updates via triggerUpdate() might not reflect on screen for LARGE and SMALL widget sizes due to a known platform bug. This issue only affects developers during testing; a fix is coming in a future release.

2. Show the tile:

adb shell am broadcast \
  -a com.google.android.wearable.app.DEBUG_SYSUI \
  --es operation show-tile \
  --ei index 0

Using the Hello Widget

The HelloWidget is a simple, static widget designed to show the minimal implementation required for a Wear Widget.

Hello Widget

To preview it on a device or emulator, follow the steps in the Add and Preview your Widget section above.

Updating the Weather Widget

The WeatherWidget demonstrates how to handle dynamic content updates. You can trigger updates in two ways:

Weather Widget

Via the In-App Control Panel

The sample includes a WeatherActivity that acts as a control panel.

  1. Launch the Weather Update app from the app launcher on your watch.
  2. Tap any of the weather condition buttons (Sunny, Cloudy, etc.) to push that state to the widget.

Via ADB Broadcast

You can simulate external data updates (like a background sync) by sending a broadcast intent via ADB.

adb shell am broadcast \
  -a com.google.example.wear_widget.UPDATE_WEATHER \
  -n com.google.example.wear_widget/.WeatherUpdateReceiver \
  --ei temp 75 \
  --es condition "'🌧️'"

Note: Depending on your terminal and OS, you may need to escape the emoji or use its unicode representation.

Support

If you've found an error in this sample, please file an issue: https://github.com/android/wear-os-samples

Patches are encouraged, and may be submitted by forking this project and submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.