- This event has passed.
6 PM – Android Game Dev – Gamas
November 12, 2025 @ 6:00 pm - 7:00 pm
Today We Did
- We continued with Weather App project.
- We fetched weather data from https://openweathermap.org/
- We get the API Key from openweathermap.org.
Homework
- Continue with MainActivity.fetchWeatherInfo(String cityName) method.
- You need to make request to openweathermap.org server and get its JSON. This is very similar with how you did with pixabay.com code below. Similar but not 100% the same. You need to modify the code when you get the json from the server.
-
OkHttpClient httpClient = new OkHttpClient(); Request request = new Request.Builder().url(url).build(); httpClient.newCall(request).enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { Log.e("MainActivity", "Error fetching city image", e); } @Override public void onResponse(Call call, Response response) throws IOException { if (response.isSuccessful()) { String jsonResponse = response.body().string(); System.out.println(jsonResponse); Gson gson = new Gson(); PixabayResponse pixabayResponse = gson.fromJson(jsonResponse, PixabayResponse.class); System.out.println("Total = "+pixabayResponse.getTotal()); System.out.println("TotalHits = "+pixabayResponse.getTotalHits()); if (!pixabayResponse.getHits().isEmpty()) { int index = random.nextInt(pixabayResponse.getHits().size()); String imageUrl = pixabayResponse.getHits().get(index).getWebformatURL(); runOnUiThread(() -> { Glide.with(MainActivity.this).load(imageUrl).into(cityImage); }); } } else { Log.e("MainActivity", "Error fetching city image: " + response.code()); } } });