Build Your Own Weather App for Wear OS Using OpenWeather API

Build Your Own Weather App for Wear OS Using OpenWeather API

Published: December 15, 2024
In this post, I’ll show you how to build a **simple yet powerful Weather App** for Wear OS smartwatches. This app will display real-time weather data (temperature, conditions, and forecasts) using the **OpenWeather API**. Whether you’re a beginner or just love building apps for your smartwatch, this tutorial will guide you step-by-step. 👉 You can reuse this logic for Android phones as well, not just Wear OS.

What This Weather App Can Do

Here’s a quick overview: -> Show the current temperature and weather condition. -> Show a small icon (sunny, rainy, cloudy, etc.) based on the condition. -> Update automatically every hour (or on-demand). -> Lightweight and battery-friendly for Wear OS.

What You’ll Need

1. A Wear OS smartwatch (or Wear OS emulator in Android Studio). 2. Android Studio installed on your PC. 3. A free OpenWeather API key. 4. Basic knowledge of how Android apps work.

Step 1: Setup a New Wear OS Project

Open Android Studio → New Project → Select Wear OS Empty Activity. This will create a starter project for your weather app.

Step 2: Get Your OpenWeather API Key

Go to OpenWeather and create a free account. Generate your API key, which you’ll use to fetch live weather data.
API_KEY=your-openweather-key

Step 3: Add Internet Permission

Open your AndroidManifest.xml and add:
<uses-permission android:name="android.permission.INTERNET" />
This allows your app to fetch data from the internet.

Step 4: Fetch Weather Data Using Retrofit

Use Retrofit (or the default `HttpURLConnection`) to call the OpenWeather API. Here’s a sample API URL:
https://api.openweathermap.org/data/2.5/weather?q=Salem&appid=YOUR_API_KEY&units=metric
This will return JSON data like temperature, humidity, and conditions.

Step 5: Show Weather on the Watch

Update your activity_main.xml with a TextView and ImageView for the icon:
<LinearLayout>
    <ImageView android:id="@+id/weatherIcon"/>
    <TextView android:id="@+id/weatherText"/>
</LinearLayout>
In your MainActivity.kt, parse the API response and display the temperature and icon.

Bonus: Auto-Update Every Hour

Use WorkManager or a simple `Handler` to refresh data every hour without user input. You can also add a refresh button on the watch face.

🔗 Related: My Full Tech Journey Blog – Learn how I started Android and Wear OS development from scratch.

Extra Features You Can Add

1. 3-day weather forecast screen. 2. Display weather based on GPS (not just a fixed city). 3. Show humidity, wind speed, and sunrise/sunset time. 4. Change background colors based on day/night or weather type.

Why This Project is Great for Beginners

This project teaches you: -> How to build apps for Wear OS (watch screens and layouts). -> How to call external APIs like OpenWeather. -> How to work with JSON responses and display data in UI. -> How to make lightweight apps that don’t drain battery.

Final Words

Now you have your own Wear OS Weather App! 👉 Get your OpenWeather API key and start building today. 👉 You can easily modify this for Android phones too. Thanks for reading! If you liked this tutorial, share it with your friends and check out my AI Assistant Tutorial

Comments