Android Weather Application using weather API and JSON data
An android application used to display weather information of different cities around the world.
Open Android Studio, create a new project, and name it. The language used is Java.
The minimum SDK used is - API 21
Creating an Android Project
Open Android Studio, create a new project, and name it. The language used is Java.
The minimum SDK used is - API 21
Creating the layout of our Application
.png)
Open activity_main.xml and paste the code of the XML file (code attached in the zip file ).
We have used Constraint Layout for our Layout in which we have used imageView for our background image, TextView, and editText for our texts and button.
Note- Download your desired background image and add it to the drawable folder.
Creating API key for our application
.png)
API keys serve as a software intermediary between two platforms. We can use API keys provided by many websites and use their data.
Here I have used OpenWeather.org and used its "City Id" - API call. You just need to sign up and create the API key for yourself and then use your OWN API KEY in the code.
Coding in our MainActivity.java
.png)
Inside our MainActivity.java -
We will add our API key in the getWeather() method and JSON data (used to send data from server to client ) in our onPostExecute () Method.
Add your API key and entered the city according to the image shown above.
Doing the necessary changes in our AndroidManifest.xml
You need to add internet permission for our application which goes by -
and also do -
android:usesCleartextTraffic="true"
.png)
After completing the code and doing the necessary changes in the manifest file, run your application in your emulator.
Project Files
| .. | ||
| This directory is empty. | ||
.png)