The Wayback Machine - https://web.archive.org/web/20240927194005/https://www.geeksforgeeks.org/how-to-create-a-covid-19-tracker-android-app/
Open In App

How to create a COVID-19 Tracker Android App

Last Updated : 25 Jun, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The world is facing one of the worst epidemics, the outbreak of COVID-19, you all are aware of that. So during this lockdown time let’s create a COVID-19 Tracker Android App using REST API which will track the Global Stats only.

Pre-requisites:



Step by Step Implementation to Create Covid-19 Tracker Android Application 

Step1: Opening a New Project 

  • Open a new project just click of File option at topmost corner in left. 
  • Then click on new and open a new project with whatever name you want. 
  • Now we gonna work on Empty Activity with language as Java. Leave all other options as untouched. 
  • You can change the name of project as per your choice. 
     

By default, there will be two files activity_main.xml and MainActivity.java.

Step 2: Before going to the coding section first you have to do some pre-task.

Go to Gradle Scripts->build.gradle (Module: app) section and import following dependencies and click the “sync Now” on the above pop up.

build.gradle (:app)

 dependencies {
// Other dependencies...
implementation 'com.android.volley:volley:1.2.1'
}

Go to app->manifests->AndroidManifests.xml section and allow “Internet Permission“.

AndroidManifests.xml

 <uses-permission android:name="android.permission.INTERNET" />

Step3: Designing the UI 

Below is the code for the xml file. 

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/color_white"
    android:orientation="vertical"
    tools:context=".MainActivity">


    <!--Linear Layout to display all the details-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="20dp"
        android:orientation="vertical">


        <!--Text view to display Global stats-->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Global Stats"
            android:textColor="#050505"
            android:textAllCaps="true"
            android:textAlignment="center"
            android:textSize="35sp"
            android:textStyle="bold"/>



            <!--Text view to display Total Cases-->
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fontFamily="sans-serif-light"
                android:layout_marginTop="20dp"
                android:text="Total Cases"
                android:textAlignment="center"
                android:textStyle="bold"
                android:textSize="30sp"/>

            <!--Text view to display the updated number when data
             will fetch from the API. For now default set to 0 -->
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="0"
                android:id="@+id/tvCases"
                android:textAlignment="center"
                android:textSize="25sp"
                android:textColor="@color/color_one"
                android:textStyle="bold"
                android:fontFamily="sans-serif-light" />

        <!--Text view to display Recovered Cases-->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="sans-serif-light"
            android:text="Recovered"
            android:textAlignment="center"
            android:textStyle="bold"
            android:textSize="30sp"/>

        <!--Text view to display the updated number when data
         will fetch from the API. For now default set to 0 -->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="0"
            android:id="@+id/tvRecovered"
            android:textAlignment="center"
            android:textSize="25sp"
            android:textColor="@color/color_one"
            android:textStyle="bold"
            android:fontFamily="sans-serif-light" />

        <!--Text view to display Critical Cases-->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="sans-serif-light"
            android:text="Critical"
            android:textAlignment="center"
            android:textStyle="bold"
            android:textSize="30sp"/>

        <!--Text view to display the updated number when data
         will fetch from the API. For now default set to 0 -->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="0"
            android:id="@+id/tvCritical"
            android:textAlignment="center"
            android:textSize="25sp"
            android:textColor="@color/color_one"
            android:textStyle="bold"
            android:fontFamily="sans-serif-light" />

        <!--Text view to display Active Cases-->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="sans-serif-light"
            android:text="Active"
            android:textAlignment="center"
            android:textStyle="bold"
            android:textSize="30sp"/>

        <!--Text view to display the updated number when data
         will fetch from the API. For now default set to 0 -->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="0"
            android:id="@+id/tvActive"
            android:textAlignment="center"
            android:textSize="25sp"
            android:textColor="@color/color_one"
            android:textStyle="bold"
            android:fontFamily="sans-serif-light" />

        <!--Text view to display Today Cases-->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="sans-serif-light"
            android:text="Today Cases"
            android:textAlignment="center"
            android:textStyle="bold"
            android:textSize="30sp"/>

        <!--Text view to display the updated number when data
         will fetch from the API. For now default set to 0 -->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="0"
            android:id="@+id/tvTodayCases"
            android:textAlignment="center"
            android:textSize="25sp"
            android:textColor="@color/color_one"
            android:textStyle="bold"
            android:fontFamily="sans-serif-light" />

        <!--Text view to display Total Deaths-->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="sans-serif-light"
            android:text="Total Deaths"
            android:textAlignment="center"
            android:textStyle="bold"
            android:textSize="30sp"/>

        <!--Text view to display the updated number when data
         will fetch from the API. For now default set to 0 -->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="0"
            android:id="@+id/tvTotalDeaths"
            android:textAlignment="center"
            android:textSize="25sp"
            android:textColor="@color/color_one"
            android:textStyle="bold"
            android:fontFamily="sans-serif-light" />

        <!--Text view to display Today Deaths-->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="sans-serif-light"
            android:text="Today Deaths"
            android:textAlignment="center"
            android:textStyle="bold"
            android:textSize="30sp"/>

        <!--Text view to display the updated number when data
         will fetch from the API. For now default set to 0 -->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="0"
            android:id="@+id/tvTodayDeaths"
            android:textAlignment="center"
            android:textSize="25sp"
            android:textColor="@color/color_one"
            android:textStyle="bold"
            android:fontFamily="sans-serif-light" />

        <!--Text view to display Affected Countries-->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="sans-serif-light"
            android:text="Affected Countries"
            android:textAlignment="center"
            android:textStyle="bold"
            android:textSize="30sp"/>

        <!--Text view to display the updated number when data
         will fetch from the API. For now default set to 0 -->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="0"
            android:id="@+id/tvAffectedCountries"
            android:textAlignment="center"
            android:textSize="25sp"
            android:textColor="@color/color_one"
            android:textStyle="bold"
            android:fontFamily="sans-serif-light" />

        </LinearLayout>

</ScrollView>


After using this code in .xml file, the UI will be like:
 

Step 4: Working with Java file

Open the MainActivity.java file there within the class, first of all create the object of TextView class. 
 

// Create the object of TextView Class 
TextView tvCases, tvRecovered, tvCritical, tvActive, tvTodayCases, tvTotalDeaths, tvTodayDeaths, tvAffectedCountries; 

Secondly inside onCreate() method, we have to link those objects with their respective id’s that we have given in .XML file.
 

// link those objects with their respective id’s that we have given in .XML file 
tvCases = findViewById(R.id.tvCases); 
tvRecovered = findViewById(R.id.tvRecovered); 
tvCritical = findViewById(R.id.tvCritical); 
tvActive = findViewById(R.id.tvActive); 
tvTodayCases = findViewById(R.id.tvTodayCases); 
tvTotalDeaths = findViewById(R.id.tvTotalDeaths); 
tvTodayDeaths = findViewById(R.id.tvTodayDeaths); 
tvAffectedCountries = findViewById(R.id.tvAffectedCountries); 

  • Create a private void fetchdata() method outside onCreate() method and define it.
  • Inside fetchdata() method the most important task is going to happen that is how we fetch the data from a third party API and implement it in our app. My request is please read thoroughly the two articles Volley Library in Android and REST API (Introduction) to understand the following concepts.
  • Create a String request using Volley Library and assign the “url” with “https://corona.lmao.ninja/v2/all” link. 
     
Java
// Create a String request using Volley Library
String url = "https:// corona.lmao.ninja/v2/all";

StringRequest request
   = new StringRequest(
      Request.Method.GET,
      url,
      new Response.Listener() {
         @Override
         public void onResponse(
            String response) {}
      },
      new Response.ErrorListener() {
         @Override
         public void onErrorResponse(
            VolleyError error) {}
      });

RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(request);


Please refer this website to take a look at the requested data are in JSON format.
 

So the next thing you have to do is, inside the onResponse() method create the object of “JSONObject” class then set the data in text view which are available in JSON format with the help of “jsonobject”. Make sure that you have to do these things inside a “try” block.

Note: Remember that the parameter inside the getString() must match with the name given in JSON format.

Java
// Handle the JSON object and handle it inside try and catch

try {
    // Creating object of JSONObject
    JSONObject jsonObject
        = new JSONObject(
            response.toString());

    // Set the data in text view
    // which are available in JSON format
    // Note that the parameter
    // inside the getString() must match
    // with the name given in JSON format
    tvCases.setText(
        jsonObject.getString("cases"));
    tvRecovered.setText(
        jsonObject.getString("recovered"));
    tvCritical.setText(
        jsonObject.getString("critical"));
    tvActive.setText(
        jsonObject.getString("active"));
    tvTodayCases.setText(
        jsonObject.getString("todayCases"));
    tvTotalDeaths.setText(
        jsonObject.getString("deaths"));
    tvTodayDeaths.setText(
        jsonObject.getString("todayDeaths"));
    tvAffectedCountries.setText(
        jsonObject.getString("affectedCountries"));
}
catch (JSONException e) {
    e.printStackTrace();
}


And inside onErrorResponse() method you have to show a toast message if any error occurred. 

Toast.makeText(MainActivity.this, error.getMessage(), Toast.LENGTH_SHORT) .show();

At last invoke the fetchdata() method inside onCreate() method. 

fetchdata();


Output:

 



Previous Article
Next Article

Similar Reads

How to Create a COVID-19 Tracker Android App to See Details of any City and State in India?
In the previous article, we have discussed How to create a COVID-19 Tracker Android App which shows only the Global Stats. In this article, we will learn how to create a COVID-19 Tracker Android App which will show the details of any city in any State in India. Details like - Total Active cases, Cured Cases, Deaths, and the total number of confirme
9 min read
How to Create a Medicine Tracker Android App with Firebase?
A medicine tracker app can be a useful tool for individuals who need to take multiple medications on a regular basis. It can help users track when they need to take their medications and provide alerts and reminders to ensure they don't miss a dose. This article will look at how to build a medicine tracker app using Kotlin and Firebase. A sample vi
8 min read
Build an Android App to Check COVID-19 Vaccination Availability
Pre-requisites: Android App Development Fundamentals for BeginnersGuide to Install and Set up Android StudioAndroid | How to Create/Start a New Project in Android Studio?Android | Running your first Android appREST API (Introduction)Volley Library in Android https://www.youtube.com/watch?v=F-E6mFPIOrY The government of India has started the biggest
12 min read
How to Build a Cryptocurrency Tracker Android App?
CryptoCurrency nowadays is in most demand and many people are investing in these currencies to get high returns. Many websites and applications provide us information about the rates of different cryptocurrencies available in the Crypto Market. In this article, we will be building a similar application in which we will be displaying the rates of di
10 min read
How to Build a Bitcoin Tracker Android App?
In this article, we will be building a Bitcoin Tracker App Project using Java and XML in Android. The application will display the current rates of Bitcoin in different countries using Bitcoin API. There are many free APIs available and for this project, we will be using API by Coinlayer. The API will return a JSON that we will parse according to o
6 min read
Project Idea - Covid-19 Bed Manager App
Bed Management in this pandemic has become an issue that almost all of the families of covid patients face. But by using the latest technology this problem can be solved, The main reason for this problem is hospitals not having a proper portal for managing beds. Our solution to this problem can be used to save many lives of covid patients. Therefor
8 min read
Health Tracker App Backend Using Node and Express.js
A Health Tracker App is a platform that allows users to log and monitor various data of their health and fitness. In this article, we are going to develop a Health Tracker App with Node.js and Express.js. that allows users to track their health-related activities such as exercise, meals, water intake, and sleep. Prerequisites:Node.jsExpress.jsMongo
4 min read
Developing a Fitness Challenge Tracker App with Leaderboard using React
In this article, we will create a Fitness Challenge Tracker App using ReactJS. The Fitness Challenge Tracker App serves as a digital companion for individuals striving to meet their fitness objectives. It allows users to record their exercise routines, track progress, and compete with others in various fitness challenges. Output Preview: Let’s have
4 min read
Build a Habit Tracker App with React and local storage
In this article, we will be Building a Habit Tracker App with React and local storage to persist habit data. The habit tracker app is a web application that helps users track their daily habits and progress over time. It provides a simple and intuitive interface for users to add new habits with descriptions, edit, remove, and mark them as completed
5 min read
Nutrition Meter - Calories Tracker App using React
GeeksforGeeks Nutrition Meter application allows users to input the name of a food item or dish they have consumed, along with details on proteins, calories, fat, carbs, etc. Users can then keep track of their calorie intake and receive a warning message if their calorie limit is exceeded. The logic for inputting item data and saving results in a c
9 min read
Note-Taking App with Status Tracker using MERN Stack
In this article, we will be creating a simple note-taking application with functionalities to create a note, delete a note, edit a note, and view the note. The project uses NodeJS as a backend server with Postman API to post and get the notes from the HTTP request. It uses ExpressJS as a framework in the backend and MongoDB to create a database and
15 min read
How to Integrate In-App Review API into Android App?
Once we publish our app over the PlayStore and as it became live there, app rating and reviews become very crucial to driving audience and downloads to your app. In order to increase this, we ask our users to rate the app through a popup window and redirecting them to the PlayStore. But this nowadays creates little problems, once users went to Play
3 min read
How to Share Text of Your App with Another App and Vice Versa in Android?
Most of the time while using an app we want to share text from the app to another app. While using Many Social Media Platforms we find this feature to be very useful when we want to share information from one app to another. The Android intent resolver is used when sending data to another app as part of a well-defined task flow. To use the Android
5 min read
How to Share Image of Your App with Another App in Android?
Most of the time while using an app we want to share images from the app to another app. While using Many Social Media Platforms we find this feature to be very useful when we want to share information from one app to another. The Android Intent resolver is used when sending data to another app as part of a well-defined task flow. To use the Androi
4 min read
Scraping COVID-19 statistics using Python and Selenium
Selenium is an open source web testing tool that allows users to test web applications across different browsers and platforms. It includes a plethora of software that developers can use to automate web applications including IDE, RC, webdriver and Selenium grid, which all serve different purposes. Moreover, it serves the purpose of scraping dynami
4 min read
Face Mask detection and Thermal scanner for Covid care - Python Project
IntroductionThe coronavirus COVID-19 pandemic is triggering a worldwide health catastrophe, hence the World Health Organization recommends wearing a face mask in designated areas. Face Mask Detection and Hand Sanitization have been a well-known subject in recent times, as well as in image preparation and computer vision. Many new computations are b
5 min read
Covid Vaccine Availability using Flask Server
In this article, we are going to build Covid Vaccine Availability Checker using Flask Server. We all are familiar that the whole world is suffering from the pandemic and the only thing which helps us to come out from this situation is mass Vaccination. But as we know due to the large population of the country it is very difficult to find vaccines i
7 min read
Android | Running your first Android app
After successfully Setting up an Android project, all of the default files are created with default code in them. Let us look at this default code and files and try to run the default app created. The panel on the left side of the android studio window has all the files that the app includes. Under the java folder, observe the first folder containi
3 min read
How to Add Audio Files to Android App in Android Studio?
The audio file format is a file format for saving digital audio data on a computer system and all are aware of audio files. So in this article, we are going to discuss how can we add audio files to the android app. There are three major groups of audio file formats: Format Name Description Examples Uncompressed audio formatsUncompressed audio forma
3 min read
Different Ways to Analyze APK Size of an Android App in Android Studio
APK size is one of the most important when we are uploading our app to Google Play. APK size must be considered to be as small as possible so users can visit our app and download our app without wasting so much data. In this article, we will take a look at How we can analyze our APK in Android Studio to check the APK size. Android Studio itself pro
3 min read
How to Build a Number Shapes Android App in Android Studio?
Android is a vast field to learn and explore and to make this learning journey more interesting and productive we should keep trying new problems with new logic. So, today we are going to develop an application in android studio which tells us about Numbers that have shapes. We will be covering two types of numbers i.e. triangular and square. So, f
4 min read
How to Build Binary to Decimal Converter Android App in Android Studio?
This app will convert a Binary Number into a Decimal Number. Some people may also have written a java program to convert a Binary Number into a Decimal Number, but while making an app let's see how to do that. Brief Go Through We will start by creating a new project with an Empty Activity. After creating a project, we would add the drawable resourc
5 min read
How to Use Stack Overflow to Fix Errors During Android App Development in Android Studio?
Stack Overflow, the life savior of developers, feels like Stack Overflow is built for the developers, by the developers, of the developers. According to Wikipedia: "Stack Overflow is a question-and-answer site for professional and enthusiast programmers". So being a developer or programmer can you imagine your life without Stack Overflowâ€Ķ. ? Most p
4 min read
How to Make a Scientific Calculator Android App using Android Studio?
The calculator is the app that is present on every android device. This app comes pre-installed or we can also install another application from Play Store. It is one of the most used applications for college students for making any calculations. In this article, we will take a look at building a simple scientific calculator app in Android using Kot
13 min read
How to Convert Any Website to Android App in Android Studio?
Here, we are going to make an application for the "GeeksForGeeks" website. By making this application we will be able to learn how we can convert a website to an Android Application just by following simple steps. You can use this concept for your personal website too and learn something new. What we are going to build in this article? In this appl
12 min read
How to Change App Icon of Android Programmatically in Android?
In this article, we are going to learn how to change the App Icon of an App on the Button Click. This feature can be used when we have an app for different types of users. Then as per the user type, we can change the App Icon Dynamically. Step by Step Implementation Step 1: Create a New Project To create a new project in Android Studio please refer
3 min read
How to Build a Prime Number Checker Android App in Android Studio?
A prime number is a natural number greater than 1, which is only divisible by 1 and itself. First few prime numbers are : 2 3 5 7 11 13 17 19 23 â€Ķ... In this article, we will be building a Prime Number Checker android app in Android Studio using Kotlin and XML. The app will check whether the entered number is a Prime number or not, if the entered w
3 min read
Build an Android App with HTML, CSS and JavaScript in Android Studio
Android is a mobile operating system based on a modified version of the Linux kernel and other open-source software, designed primarily for touchscreen mobile devices such as smartphones and tablets. Yes, you read it right in the title of this article. In this article, we are going to build an Android App with HTML, CSS, and JavaScript in Android S
2 min read
Creating a Anagram Checker Android App in Android Studio with Kotlin
An anagram of a word is another word that contains the same characters, only the order of characters can be different. For example, “abcd” and “dabc” are an anagram of each other. In this article, we will be building an Anagram Checker android app in Android Studio using Kotlin and XML. The app will check whether the entered words are anagrams of e
3 min read
Java For Android - Building Your First Android App
Android app development can play a major role in writing the app functionalities using Java programming. Every activity can be designed with Java programming. Android apps are developed using the Android Studio IDE, which provides the environment for Java development for Android programming. PrerequisitesJava ProgrammingAndroid Studio in your syste
5 min read
Practice Tags :