Go digital with E-Gram Panchayat Services on Android

The E-Gram Panchayat Android app is an essential tool for local government administration in India. It aims to provide a platform that connects citizens and the members of Panchayat. With the help of this app, citizens can easily lodge complaints, track ongoing projects, and receive updates on upcoming events or programs.

The app is built using Java as the primary programming language and leverages Firebase Realtime Database, Firebase Storage, Firebase Authentication, Picasso library, and Android Image cropper to provide a seamless user experience.

About Android E-Gram Panchayat Services App

The objective of this project is to provide a step-by-step guide on how to develop an E-Gram Panchayat Android app.

The project will cover the necessary features and functionalities, including the admin and user modules, login, complaint registration, ongoing projects, upcoming events, and contact details. The app will also have an admin module to manage user details and update the latest government schemes.

Prerequisites for E-Gram Panchayat Services App using Android

To follow this project, you should have a basic understanding of Java programming, Android Studio, and Firebase. You should also have an active Firebase account and Android Studio installed on your system.

Additionally, you should be familiar with the Android SDK, as well as the concepts of Firebase Realtime Database, Firebase Storage, Firebase Authentication, Picasso library, and Android Image cropper.

Download Android E-Gram Panchayat Services Project

Please download the source code of Android E-Gram Panchayat Services project from the following link: Android E-Gram Panchayat Services

Steps to Create Android E-Gram Panchayat Services App using Android

Following are the steps for developing the Android E-Gram Panchayat Services project:

Step 1:

Creating the android project using java as the language and adding the firebase library using the inbuilt firebase library assistant in the Android Studio.

gram panchayat output

Also add the following dependencies in your project in the app level gradle file as shown below.

api 'com.squareup.picasso:picasso:2.8'
  implementation "com.theartofdev.edmodo:android-image-cropper:2.8.+"

android-gram-panchayat-output

Step 2:

Creating Main page, Login page and Registration page layout and handling the login and registration task using the firebase authentication and firebase realtime database.

Main Page Layout

main page layout output

Activity to handle Main Page

// Importing the required packages
package com.techvidvan.grampanchayat;

// Importing the required libraries
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;

import com.google.firebase.auth.FirebaseAuth;

// Creating the MainActivity class and extending it with the AppCompatActivity class
public class MainActivity extends AppCompatActivity {

    // Creating the required variables
    private Button register;
    private Button login;
    private Button admin;

    // Overriding the onCreate method
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Setting the content view to the activity_main layout
        setContentView(R.layout.activity_main);

        // Initializing the variables with the required views
        register = findViewById(R.id.registerButton);
        login = findViewById(R.id.loginButton);
        admin = findViewById(R.id.adminLoginButton);


        // Setting the onClickListener to the register button and moving to the RegisterActivity
        // If user clicks on the register button, the app will move to the RegisterActivity
        register.setOnClickListener(v -> {
            startActivity(new Intent(MainActivity.this, RegisterActivity.class));

        });

        // Setting the onClickListener to the login button and moving to the LoginActivity
        // If user clicks on the login button, the app will move to the LoginActivity
        login.setOnClickListener(v -> {
            startActivity(new Intent(MainActivity.this, LoginActivity.class));
        });

        // Setting the onClickListener to the admin button and moving to the AdminLoginActivity
        // If user clicks on the admin button, the app will move to the AdminLoginActivity
        admin.setOnClickListener(v -> {
            startActivity(new Intent(MainActivity.this, AdminLoginActivity.class));
        });

    }


    @Override
    protected void onStart() {
        super.onStart();

        // Checking if the user is already logged in
        // If the user is already logged in, the app will move to the HomeActivity
        if(FirebaseAuth.getInstance().getCurrentUser() != null){
            Intent intent = new Intent(MainActivity.this, HomeActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            startActivity(intent);
            finish();
        }
    }
}

Login Page Layout

log in output

Activity to handle login

// Importing the required packages
package com.techvidvan.grampanchayat;

// Importing the required libraries
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
import com.google.android.material.textfield.TextInputLayout;

// Creating the AdminLoginActivity class and extending it with the AppCompatActivity class
public class AdminLoginActivity extends AppCompatActivity {

    // Creating the required variables
    private TextInputLayout adminID, adminPassword;
    private Button id_login;
    private ProgressBar progressBar;
    private FirebaseAuth auth;

    // Overriding the onCreate method
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Setting the content view to the activity_admin_login layout
        setContentView(R.layout.activity_admin_login);

        // Initializing the variables with the required views
        id_login = findViewById(R.id.id_login);
        adminID = findViewById(R.id.adminID);
        adminPassword = findViewById(R.id.adminPassword);
        progressBar = findViewById(R.id.progressBar);

        // Initializing the FirebaseAuth instance
        auth = FirebaseAuth.getInstance();

        // Setting the onClickListener to the id_login button and performing the required operations
        id_login.setOnClickListener(v -> {
            String ID = adminID.getEditText().getText().toString();
            String Password = adminPassword.getEditText().getText().toString();

            // Validating the input fields
            if (ID.isEmpty()) {
                adminID.setError("Email is required");
                adminID.requestFocus();
                return;
            } else {
                adminID.setError(null);
            }
            if (Password.isEmpty()) {
                adminPassword.setError("Password is required");
                adminPassword.requestFocus();
                return;
            } else {
                adminPassword.setError(null);
            }

            // Setting the visibility of the progress bar to visible
            progressBar.setVisibility(View.VISIBLE);

            // Checking if the entered credentials are correct or not for the admin
            if (ID.equals("[email protected]") && Password.equals("hello@1234")) {

                // Signing in with the entered credentials
                auth.signInWithEmailAndPassword("[email protected]", "hello@1234")
                        .addOnCompleteListener(task -> {

                            // Checking if the task is successful or not
                            if(task.isSuccessful()){

                                // Setting the visibility of the progress bar to gone and starting the HomeActivity
                                // Toast message is displayed if the entered credentials are correct
                                progressBar.setVisibility(View.GONE);
                                Intent intent = new Intent(AdminLoginActivity.this, HomeActivity.class);

                                Toast.makeText(getApplicationContext(), "Login Successful", Toast.LENGTH_SHORT).show();
                                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                                startActivity(intent);
                                finish();

                            }
                        });
            } else {

                // Setting the visibility of the progress bar to gone and displaying the error message
                // if the entered credentials are incorrect
                Toast.makeText(AdminLoginActivity.this, "Invalid Credentials", Toast.LENGTH_SHORT).show();
                progressBar.setVisibility(View.GONE);
            }

        });

    }
}

Registration Page Layout

registration output

Activity to handle registration

// Importing the required packages
package com.techvidvan.grampanchayat;

// Importing the required libraries
import androidx.appcompat.app.AppCompatActivity;

import java.util.Calendar;
import java.util.regex.Pattern;

import android.app.DatePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Patterns;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.functions.FirebaseFunctions;
import com.techvidvan.grampanchayat.data.model.User;


// Creating the RegisterActivity class and extending it with the AppCompatActivity class
public class RegisterActivity extends AppCompatActivity {

    // Creating the required variables
    private TextInputLayout tEmail, tPassword, tConfirmPassword, tName, tContact, tDateOfBirth, tAddress, tAadhar, tPincode;
    private TextInputEditText tDOB;
    private ProgressBar pb;
    private Button register;
    private TextView signIn;
    private RadioGroup tgender;
    private RadioButton tMale, tFemale, tOther;
    private FirebaseDatabase database;
    private FirebaseAuth auth;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        // Setting the content view to the activity_register layout
        setContentView(R.layout.activity_register);
        
        // Initializing the FirebaseAuth instance and the FirebaseDatabase instance
        auth = FirebaseAuth.getInstance();
        database = FirebaseDatabase.getInstance();
        
        // Initializing the variables with the required views
        tEmail = (TextInputLayout) findViewById(R.id.id_emailRegister);
        tPassword = (TextInputLayout) findViewById(R.id.id_pwdRegister);
        tConfirmPassword = (TextInputLayout) findViewById(R.id.id_confirmpwdRegister);
        tName = (TextInputLayout) findViewById(R.id.id_userName);
        tContact = (TextInputLayout) findViewById(R.id.id_contactNo);
        tDateOfBirth = (TextInputLayout) findViewById(R.id.id_dob);
        tDOB = (TextInputEditText) findViewById(R.id.id_dob_edittext);
        tAddress = (TextInputLayout) findViewById(R.id.id_address);
        tAadhar = (TextInputLayout) findViewById(R.id.id_aadharno);
        tPincode = (TextInputLayout) findViewById(R.id.id_pincode);
        tgender = (RadioGroup) findViewById(R.id.radioGroup);
        tMale = (RadioButton) findViewById(R.id.id_male);
        tFemale = (RadioButton) findViewById(R.id.id_female);
        tOther = (RadioButton) findViewById(R.id.id_other);
        pb = (ProgressBar) findViewById(R.id.progressBar2);
        register = (Button) findViewById(R.id.id_register);
        signIn = (TextView) findViewById(R.id.id_signInRegister);
        
        
        // Setting the onClickListener for the signIn TextView to open the LoginActivity
        // when the user clicks on the signIn TextView
        signIn.setOnClickListener(v -> {
            startActivity(new Intent(RegisterActivity.this, LoginActivity.class));
        });
        
        // Setting the onClickListener for the tDOB TextInputEditText to open the DatePickerDialog
        // when the user clicks on the tDOB TextInputEditText (Date of Birth)
        tDOB.setOnClickListener(v -> {
            
            // Creating the Calendar instance and getting the current date
            final Calendar c = Calendar.getInstance();
            int year = c.get(Calendar.YEAR);
            int month = c.get(Calendar.MONTH);
            int day = c.get(Calendar.DAY_OF_MONTH);
            
            // Creating the DatePickerDialog instance and setting the date to the DatePickerDialog
            DatePickerDialog datePickerDialog = new DatePickerDialog(RegisterActivity.this, (view, year1, monthOfYear, dayOfMonth) -> {
                // Setting the date to the tDOB TextInputEditText
                tDateOfBirth.getEditText().setText(dayOfMonth + "-" + (monthOfYear + 1) + "-" + year1);
            }, year, month, day);
            
            // Showing the DatePickerDialog
            datePickerDialog.show();

        });
        
        // Setting the onClickListener for the register Button to register the user
        // when the user clicks on the register Button
        register.setOnClickListener(v -> {
            
            // Initializing the required variables
            String email = tEmail.getEditText().getText().toString();
            String password = tPassword.getEditText().getText().toString();
            String confirmPassword = tConfirmPassword.getEditText().getText().toString();
            String name = tName.getEditText().getText().toString();
            String contact = tContact.getEditText().getText().toString();
            String address = tAddress.getEditText().getText().toString();
            String aadhar = tAadhar.getEditText().getText().toString();
            String pincode = tPincode.getEditText().getText().toString();
            int genderID = tgender.getCheckedRadioButtonId();
            String dateOfBirth = tDateOfBirth.getEditText().getText().toString();
            String gender = "";
            
            
            // Registration Validation 
            if (name.isEmpty()) {
                tName.setError("Name is required");
                tName.requestFocus();
                return;
            } else {
                tName.setError(null);
            }
            if (contact.isEmpty()) {
                tContact.setError("Phone number is required");
                tContact.requestFocus();
                return;
            } else {
                tContact.setError(null);
            }
            if (contact.length() != 10) {
                tContact.setError("Enter a valid phone number");
                tContact.requestFocus();
                return;
            } else {
                tContact.setError(null);
            }
            if (dateOfBirth.isEmpty()) {
                tDateOfBirth.setError("Date of Birth is required");
                tDateOfBirth.requestFocus();
                return;
            } else {
                tDateOfBirth.setError(null);
            }
            if (aadhar.isEmpty()) {
                tAadhar.setError("Aadhar is required");
                tAadhar.requestFocus();
                return;
            } else {
                tAadhar.setError(null);
            }
            if (aadhar.length() != 12) {
                tAadhar.setError("Enter a valid Aadhar number");
                tAadhar.requestFocus();
                return;
            } else {
                tAadhar.setError(null);
            }
            if (genderID == -1) {
                tgender.requestFocus();
                return;
            }
            if (tMale.isChecked()) {
                gender = "Male";
            } else if (tFemale.isChecked()) {
                gender = "Female";
            } else if (tOther.isChecked()) {
                gender = "Other";
            }
            if (address.isEmpty()) {
                tAddress.setError("Address is required");
                tAddress.requestFocus();
                return;
            }
            if (pincode.isEmpty()) {
                tPincode.setError("Pincode is required");
                tPincode.requestFocus();
                return;
            }
            if (pincode.length() != 6) {
                tPincode.setError("Enter a valid Pincode");
                tPincode.requestFocus();
                return;
            }
            if (email.isEmpty()) {
                tEmail.setError("Email is required");
                tEmail.requestFocus();
                return;
            }
            Pattern pattern = Pattern.compile("[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+");
            if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
                tEmail.setError("Enter a valid email");
                tEmail.requestFocus();
                return;
            }
            if (password.isEmpty()) {
                tPassword.setError("Password is required");
                tPassword.requestFocus();
                return;
            }
            if (confirmPassword.isEmpty()) {
                tConfirmPassword.setError("Confirm Password is required");
                tConfirmPassword.requestFocus();
                return;
            }
            if (password.length() < 8) {
                tPassword.setError("Password should be at least 8 characters");
                tPassword.requestFocus();
                return;
            }
            if (!password.matches(".*[0-9].*")) {
                tPassword.setError("Password should contain at least one number");
                tPassword.requestFocus();
                return;
            }
            if (!password.matches(".*[a-zA-Z].*")) {
                tPassword.setError("Password should contain at least one alphabet");
                tPassword.requestFocus();
                return;
            }
            
            // Checking if the password and confirm password are same
            if (password.equals(confirmPassword)) {
                
                // Calling the registerUser method to register the user
                registerUser(email, password, name, aadhar, address, contact, pincode, dateOfBirth, gender);
            } else {
                
                // Showing the error message if the password and confirm password are not same
                Toast.makeText(RegisterActivity.this, "Password and Confirm Password should be same", Toast.LENGTH_SHORT).show();
            }


        });

    }
    
    // Method to register the user in the Firebase Authentication
    private void registerUser(String email, String password, String name, String aadhar, String address, String contact, String pincode, String dateOfBirth, String gender) {
        pb.setVisibility(View.VISIBLE);
        
        // Creating the user in the Firebase Authentication
        auth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(task -> {
            if (task.isSuccessful()) {
                
                // Creating the user in the Firebase Realtime Database if the user is created in the Firebase Authentication
                User user = new User(email, name, aadhar, address, contact, pincode, dateOfBirth, gender);
                FirebaseDatabase.getInstance().getReference("Users").child(FirebaseAuth.getInstance().getCurrentUser().getUid()).setValue(user).addOnCompleteListener(task1 -> {
                    if (task1.isSuccessful()) {
                        
                        // Showing the success message and redirecting the user to the login page
                        pb.setVisibility(View.GONE);
                        Toast.makeText(RegisterActivity.this, "User has been registered successfully!", Toast.LENGTH_LONG).show();

                        Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                        startActivity(intent);
                        finish();
                    }
                    
                });
            }
            
        }).addOnFailureListener(e -> {
            
            // Showing the error message if the user is not created in the Firebase Authentication
            pb.setVisibility(View.GONE);
            Toast.makeText(RegisterActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
        });
    }
}

Admin Login Page Layout

admin login page output

Activity to handle Admin login

// This class is used to check whether the user is admin or not

// Importing the required packages
package com.techvidvan.grampanchayat.data.model;

// Creating the Admin class
public class Admin {
  
   // Creating the required variables and assigning the admin UID and email
   String adminUid = "HJj7hgcA6xZFgWdFQAz61vGVYsk1";
   String adminMail = "[email protected]";
  
   // Creating the isAdminUsingUID method to check
   // whether the user is admin or not using the UID
   public boolean isAdminUsingUID(String uid){
       if (adminUid.equals(uid)){
           return true;
       }
       return false;
   }
  
   // Creating the isAdminUsingMail method to check
   // whether the user is admin or not using the email
   public boolean isAdminUsingMail(String mail){
       if (adminMail.equals(mail)){
           return true;
       }
       return false;
   }


}

Step 4:

Creating Navigation Drawer Layout using the Android Studio inbuilt activity creator and customizing it according to the needs. The activity for the Navigation Drawer is named HomeActivity.java.

android e gram panchayat output

After customizing the Drawer layout it will look like this

android e gram output

HomeActivity.java

This is an Android app’s main activity that sets up the home screen. The important parts of the code include:

  • Importing required packages and libraries.
  • Initializing the binding variable and setting the content view.
  • Setting up the toolbar as the action bar and the navigation controller to the navigation view.
  • Implementing the menu, including a logout button that opens a confirmation dialog box and signs the user out of the app.
  • Checking if the user is verified and redirecting them to the login activity if they are not.
  • Retrieving the user’s profile image from Firebase Storage and displaying it in the navigation drawer.
  • Hiding menu options according to the user Role.

Code for the HomeActivity.java

// This is the main activity of the app. It is the home screen of the app.

// Importing all the required packages
package com.techvidvan.grampanchayat;

// Importing all the required libraries
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.Menu;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.navigation.NavigationView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import com.squareup.picasso.Picasso;
import com.techvidvan.grampanchayat.data.model.Admin;
import com.techvidvan.grampanchayat.databinding.ActivityHomeBinding;

import androidx.annotation.NonNull;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.appcompat.app.AppCompatActivity;

// HomeActivity class which extends AppCompatActivity
public class HomeActivity extends AppCompatActivity {

    // Declaring all the variables
    private AppBarConfiguration mAppBarConfiguration;
    private ActivityHomeBinding binding;

    StorageReference storageReference;


    // onCreate method which is called when the activity is created
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Initializing the binding variable
        binding = ActivityHomeBinding.inflate(getLayoutInflater());

        // Setting the content view
        setContentView(binding.getRoot());

        // Setting the toolbar as the action bar
        setSupportActionBar(binding.appBarHome.toolbar);
        DrawerLayout drawer = binding.drawerLayout;
        NavigationView navigationView = binding.navView;

        // Passing each menu ID as a set of Ids because each menu should be considered as top level destinations.
        mAppBarConfiguration = new AppBarConfiguration.Builder(
                R.id.nav_home,R.id.nav_profile, R.id.nav_edit_profile, R.id.nav_create_news, R.id.nav_file_complaint, R.id.nav_view_your_complaint, R.id.nav_pending_complaints, R.id.nav_view_all_complaints_resolved, R.id.nav_view_all_complaints_rejected)
                .setOpenableLayout(drawer)
                .build();

        // Setting the navigation controller to the navigation view
        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_home);
        NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
        NavigationUI.setupWithNavController(navigationView, navController);


    }

    // onCreateOptionsMenu method which is called when the options menu is created
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.home, menu);

        // Setting the on click listener for the logout button
        menu.getItem(0).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {

                // Creating an alert dialog box to confirm the logout
                AlertDialog.Builder builder = new AlertDialog.Builder(HomeActivity.this);
                builder.setTitle("Confirm");
                builder.setMessage("Are you sure? You want to logout?");
                builder.setPositiveButton("YES", (dialog, which) -> {

                    // Signing out the user and redirecting to the login activity
                    // if the user clicks on the yes button
                    FirebaseAuth.getInstance().signOut();

                    // Redirecting to the login activity
                    startActivity(new Intent(HomeActivity.this, LoginActivity.class));
                    finish();

                    // Dismissing the dialog box
                    dialog.dismiss();
                });

                // If the user clicks on the no button, the dialog box is dismissed
                builder.setNegativeButton("NO", (dialog, which) -> {
                    dialog.dismiss();
                });

                // Creating and showing the alert dialog box
                AlertDialog alert = builder.create();
                alert.show();

                return false;
            }
        } );

        return true;
    }

    // onSupportNavigateUp method which is called when the navigation up button is clicked
    @Override
    public boolean onSupportNavigateUp() {
        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_home);
        return NavigationUI.navigateUp(navController, mAppBarConfiguration)
                || super.onSupportNavigateUp();
    }

    // onStart method which is called when the activity is started
    // We are checking if the user is verified or not in this method
    @Override
    protected void onStart() {
        super.onStart();
        NavigationView navigationView = binding.navView;

        // Getting the current user from the firebase authentication
        FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

        // If the user is not verified, the user is redirected to the login activity
        if(!user.isEmailVerified()){
            startActivity(new Intent(HomeActivity.this, LoginActivity.class));
            finish();
        }

        //retrieve user profile image from firebase storage "profileImages" node using user id
        View headerView = navigationView.getHeaderView(0);
        ImageView id_profileImage = (ImageView) headerView.findViewById(R.id.profile_image);

        // Initializing the firebase authentication and storage reference
        FirebaseAuth  auth = FirebaseAuth.getInstance();
        storageReference = FirebaseStorage.getInstance().getReference();

        // Getting the download url of the profile image
        StorageReference profileRef = storageReference.child("profileImages/" + auth.getCurrentUser().getUid());

        // Setting the profile image using the picasso library
        profileRef.getDownloadUrl().addOnSuccessListener(uri -> {
            Picasso.get().load(uri).into(id_profileImage);
        });

        // Retrieving the user name and email from the firebase realtime database
        final FirebaseDatabase database = FirebaseDatabase.getInstance();
        DatabaseReference db = database.getReference().child("Users").child(user.getUid());
        db.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot snapshot) {

                // Getting the user name and email from the firebase realtime database
                String name = snapshot.child("name").getValue().toString();
                String email = snapshot.child("email").getValue().toString();

                // Setting the user name and email in the navigation view header
                View headerView = navigationView.getHeaderView(0);
                TextView navEmail = (TextView) headerView.findViewById(R.id.mail);
                TextView navUsername = (TextView) headerView.findViewById(R.id.name);
                navUsername.setText(name);
                navEmail.setText(email);

            }

            // If the data is not retrieved, the onCancelled method is called
            @Override
            public void onCancelled(@NonNull DatabaseError error) {

            }
        });

        // Checking if the user is an admin or not and displaying the menu items accordingly
        Admin currentUser = new Admin();
        Menu nav_Menu = navigationView.getMenu();

        if(currentUser.isAdminUsingUID(user.getUid())){

            // If the user is an admin, the following menu items are displayed
            nav_Menu.findItem(R.id.nav_pending_complaints).setVisible(true);
            nav_Menu.findItem(R.id.nav_view_all_complaints_resolved).setVisible(true);
            nav_Menu.findItem(R.id.nav_view_all_complaints_rejected).setVisible(true);
            nav_Menu.findItem(R.id.nav_create_news).setVisible(true);

            // If the user is an admin, the following menu items are hidden
            nav_Menu.findItem(R.id.nav_file_complaint).setVisible(false);
            nav_Menu.findItem(R.id.nav_view_your_complaint).setVisible(false);
        } else {

            // If the user is not an admin, the following menu items are displayed
            nav_Menu.findItem(R.id.nav_pending_complaints).setVisible(false);
            nav_Menu.findItem(R.id.nav_view_all_complaints_resolved).setVisible(false);
            nav_Menu.findItem(R.id.nav_view_all_complaints_rejected).setVisible(false);
            nav_Menu.findItem(R.id.nav_create_news).setVisible(false);

            // If the user is not an admin, the following menu items are hidden
            nav_Menu.findItem(R.id.nav_file_complaint).setVisible(true);
            nav_Menu.findItem(R.id.nav_view_your_complaint).setVisible(true);
        }

    }
}

After doing this, Navigation Drawer will look something like this to the Admin and normal User.

Admin Navigation Drawer View

navigation output

Normal user Navigation Drawer View

navigation drawer output

Step 5:

Now, We will customize the fragments layouts that are in the drawer.

1. fragment_home.xml: It is the home fragment where users will see the Upcoming projects and Services. If the user clicks on the item. It will Show them a full news article. Newly created news will be shown at the top of the list.

fragement output

2. fragment_news_read.xml: This fragment will be displayed when the user clicks on the Article on the home page. If the current user is admin, it will show the option to delete the news from the database.

fragement news output

3. Fragment_create_news.xml: This fragment will allow the admin to Create a news about upcoming projects and Services and how the users can approach it. This fragment will only be visible to the Admin.

fragement create output

create new output

4. Fragment_profile.xml: This fragment will show the user/admin its profile details like, name, address, profile photo, contact number, etc.

fragement profile output

5. Fragment_edit_profile.xml: This fragment will allow the user/admin to edit their profile details like profile image, name, date of birth, etc.

fragement edit output

6. Fragment_file_complaint.xml: This fragment will allow the user to file a complaint. It will only be visible to the normal user.

file complaint output

7. Fragment_user_complaint.xml: This fragment will show the user their previous complaint details and its status and feedback from the admin. Newly created complaints will be shown at the top of the list.

user complaint output

8. Fragment_pending_complaint.xml: This fragment will show the admin all the pending complaints that are yet to be resolved.

pending complaint output

9. Fragment_resolved_complaint.xml: This fragment will show the admin all the resolved complaints so far.

resolved complaint output

10. Fragment_rejected_complaint.xml: This fragment will show the admin all the rejected complaints.

reject complaint output

11. Fragment_read_complaint.xml: If user/admin clicks on any complaints in the lists of complaints, they will be able to read the complaint. If the user is Admin, it will show them the ability to respond to the complaint by setting its status and providing feedback.

read complaint output

fragement read output

After Completing this, the file structure will look like this

e gram panchayat output

android e gram panchayat project output

Now, gram panchayat app is ready use.

Summary

The E-Gram Panchayat Android app is a must-have tool for local government administration in India. It provides a platform that connects citizens and members of Panchayat, enabling them to communicate effectively.

This project aims to provide a comprehensive guide on developing this app, leveraging Java as the primary programming language, Firebase Realtime Database, Firebase Storage, Firebase Authentication, Picasso library, and Android Image cropper. With this project, you will be able to develop an app that can lodge complaints, track ongoing projects, provide updates on upcoming events, and manage user details.