Skip to content

Exercise 15 - Weather Wear App

Project name : E15 Weather Wear app

Purpose

The purpose of this exercise is to create a Wear/Watch application which shows a weather forecast.

!Image 09

Tip

Android Developer site has an excellent material for the Wear OS.

Create a new project

  • Start Android Studio
  • Click Next, and select Wear OS Template and Blank Activity

!Image 01

  • Configure your project and in the Minimum SDK list, select the latest available option

Note

Name it E15 Weather Wear app (old naming in below picture)

!Image 02

Dependencies

Open your project build.gradle file and check that your project is using the latest version of wearable libraries. Android Studio will notify you if you don't have latest version in your dependencies section.

Manifest

Check your project manifest file and look the differences vs normal Android application.

  • Describes a standalone application
  • Uses watch hardware
  • Uses wearable library
  • Users WAKE_LOCK permission

Wear OS Emulator

Open AVD Manager and create a new virtual device for Wear OS. You can select any version you like!

!Image 10

Select a system image.

!Image 11

Note

You might need to download system image first.

And finally verify your configuration and create your AVD.

!Image 12

Run and test

In the Android Studio toolbar, select the AVD you just created from the target device drop-down menu, then click Run.

 

The AVD starts and, after a few moments, runs your app. A "Hello..." message is displayed.

Create custom layouts for Wear

With Wear OS by Google, creating layouts for a watch is similar to creating them for a phone, except that you have to design for the screen size and for glanceability. Do not port the functionality and UI from a phone app to a watch and expect a good experience.

You should create custom layouts only when necessary. Read the Designing for Wear OS guidelines for information on designing great watch apps.

The Wear UI Library is automatically included when you create your watch app with the Android Studio Project Wizard.

1
2
3
4
dependencies {
  //...
  compile 'androidx.wear:wear:VERSION_CODE_HERE'
}

Modify your UI to show Weather Forecast with text and image.

!Image 08

Click image to see it bigger!

For more information, see Create custom UIs for Wear devices.

Load Weather Forecast

Look previous exercises codes and implement weather forecast data loading in your Wear App.

Tip

You can use one city in this exercise.

Run and test

Launch your application and it should display weather forecast from your selected city.

!Image 09

Test and push

Test your application in emulator, take screenshots and commit/push your project and screenshots back to JAMKIT/GitLab. Remember move your exercise/issue ticket from Doing to In Review in Issues Board and write your learning comments to issue comments.