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.
Comments