Open In App

How to Get Bank Details from IFSC Code in Android?

Last Updated : 26 Mar, 2025
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report

Many apps such as the E-commerce app requires to accept payments from their users for providing different products or services or for their users. So this apps requires the users to enter bank details for payments. In this payment gateway, users are asked to add their banks IFSC code to get the details of their banks. So many apps have features inside their app that while entering the bank IFSC code the user's bank details such as Bank address, bank city, and other common details are fetched from that IFSC code. So in this article, we will take a look at How we can get the common bank details from the IFSC code in Android. 

What are we going to build in this article? 

We will be building a simple application in which we will be getting IFSC code from the user via an EditText and after that, the user has to click on a simple button to get the data from that IFSC code such as Bank address, bank MICR code, contact number, and other details. For performing this task we will be using a simple API which we will add to our application. This application will provide us the basic data from API which is related to the bank.

Step by Step Implementation

Step 1: Create a new project in Android Studio

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.

Step 2: Add dependency for API calling

Below is the dependency for Volley which we will be using to get the data from API. For adding this dependency navigate to the app > Gradle Scripts > build.gradle.kts (Module :app) and add the below dependency under the dependencies {} scope.    

dependencies {
...
implementation("com.android.volley:volley:1.2.1")
}

After adding this dependency sync your project.


Step 3: Adding Internet Permission

Open your AndroidManifest.xml file inside app > manifests folder. Inside your AndroidManifest.xml you need to add internet permission to access the internet.

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


Step 4: Working with the activity_main.xml file

Navigate to app > res > layout > activity_main.xml file and add the following code.

activity_main.xml:

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:hint="Enter IFSC code"
        android:inputType="textCapCharacters"
        android:maxLines="1"
        android:singleLine="true"
        android:textAllCaps="true" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="25dp"
        android:text="Get Bank Details"
        android:textAllCaps="false" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:padding="10dp"
        android:text="your details goes here..."
        android:textAlignment="viewStart"
        android:textAllCaps="false"
        android:textSize="20sp" />

</LinearLayout>

Design UI:

ifsc-details


Step 5: Working with the MainActivity file

Go to the MainActivity file and refer to the following code. Below is the code for the MainActivity.java file. Comments are added inside the code to understand the code in more detail.

MainActivity.java
package org.geeksforgeeks.demo;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONObject;

public class MainActivity extends AppCompatActivity {
    private EditText editText;
    private Button button;
    private TextView textView;
    private String ifscCode;
    private RequestQueue requestQueue;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        editText = findViewById(R.id.editText);
        button = findViewById(R.id.button);
        textView = findViewById(R.id.textView);

        // Initialize request queue
        requestQueue = Volley.newRequestQueue(this);

        button.setOnClickListener(v -> {
            
            // Get user input
            ifscCode = editText.getText().toString().trim();

            if (TextUtils.isEmpty(ifscCode)) {
                Toast.makeText(this, "Please enter a valid IFSC code", Toast.LENGTH_SHORT).show();
            } else {
                getDataFromIFSCCode(ifscCode);
            }
        });
    }

    // Function to fetch and display bank details
    private void getDataFromIFSCCode(String ifscCode) {
        
        // Clear request queue cache
        requestQueue.getCache().clear();

        // API URL to fetch details
        String url = "https://ifsc.razorpay.com/" + ifscCode;

        // Creating a JSON object request
        JsonObjectRequest objectRequest = new JsonObjectRequest(
                Request.Method.GET, url, null,
                response -> {
                    try {
                        
                        // Extracting details from the JSON response
                        String state = response.optString("STATE", "N/A");
                        String bankName = response.optString("BANK", "N/A");
                        String branch = response.optString("BRANCH", "N/A");
                        String address = response.optString("ADDRESS", "N/A");
                        String contact = response.optString("CONTACT", "N/A");
                        String micrCode = response.optString("MICR", "N/A");
                        String city = response.optString("CITY", "N/A");

                        // Display the data in the TextView
                        textView.setText(
                                "Bank Name: " + bankName +
                                "\nBranch: " + branch +
                                "\nAddress: " + address +
                                "\nMICR Code: " + micrCode +
                                "\nCity: " + city +
                                "\nState: " + state +
                                "\nContact: " + contact
                        );
                    } catch (Exception e) {
                        e.printStackTrace();
                        textView.setText("Invalid IFSC Code");
                    }
                },
                error -> textView.setText("Invalid IFSC Code")
        );

        // Add request to queue
        requestQueue.add(objectRequest);
    }
}
MainActivity.kt
package org.geeksforgeeks.demo

import android.os.Bundle
import android.text.TextUtils
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.android.volley.Request
import com.android.volley.RequestQueue
import com.android.volley.toolbox.JsonObjectRequest
import com.android.volley.toolbox.Volley

class MainActivity : AppCompatActivity() {
    private lateinit var editText: EditText
    private lateinit var button: Button
    private lateinit var textView: TextView

    private lateinit var ifscCode: String
    private lateinit var requestQueue: RequestQueue

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        editText = findViewById(R.id.editText)
        button = findViewById(R.id.button)
        textView = findViewById(R.id.textView)

        // initialize request queue
        requestQueue = Volley.newRequestQueue(this)

        button.setOnClickListener {
            // get user input
            ifscCode = editText.text.toString()

            if (TextUtils.isEmpty(ifscCode)) {
                Toast.makeText(this, "Please enter valid IFSC code", Toast.LENGTH_SHORT).show()
            } else {
                getDataFromIFSCCode(ifscCode)
            }
        }
    }

    // function to display details
    private fun getDataFromIFSCCode(ifscCode: String) {
    
        // clearing cache of request queue.
        requestQueue.cache.clear()

        // url to get response in json format
        val url = "https://ifsc.razorpay.com/$ifscCode"

        // initialize request queue
        val queue = Volley.newRequestQueue(this)

        // creating a json object request for API
        val objectRequest = JsonObjectRequest(
            Request.Method.GET, url, null, { response ->
            
                // get the response from the API.
                try {
                
                    // if status is successful extract data from JSON file
                    val state = response.optString("STATE")
                    val bankName = response.optString("BANK")
                    val branch = response.optString("BRANCH")
                    val address = response.optString("ADDRESS")
                    val contact = response.optString("CONTACT")
                    val micrCode = response.optString("MICR")
                    val city = response.optString("CITY")

                    // display data in text view
                    textView.text = (buildString {
                        append("Bank Name : ")
                        append(bankName)
                        append("\nBranch : ")
                        append(branch)
                        append("\nAddress : ")
                        append(address)
                        append("\nMICR Code : ")
                        append(micrCode)
                        append("\nCity : ")
                        append(city)
                        append("\nState : ")
                        append(state)
                        append("\nContact : ")
                        append(contact)
                    }.trimIndent())
                } catch (e: Exception) {
                    e.printStackTrace()
                    textView.text = "Invalid IFSC Code"
                }
            }, {
                textView.text = "Invalid IFSC Code"
            }
        )
        
        // add object request to request queue
        queue.add(objectRequest)
    }
}

 Output:


Similar Reads