Open In App

How to Get Bank Details from IFSC Code in Android?

Last Updated : 03 Jan, 2023
Like Article

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 we are 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 be added to our application. This application will provide us the basic data from API which is related to the bank. Below is the GIF image in which we will get to see what we are going to build in this article. Note that we are going to implement this project using the Java language. 

 Get Bank Details from IFSC Code in Android Sample GIF

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. Note that select Java as the programming language.

Step 2: Add the below dependency in your build.gradle file  

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(app) and add the below dependency in the dependencies section.    

implementation ‘’

After adding this dependency sync your project and now move toward the XML part.  

Step 3: Working with the activity_main.xml file

Go to the activity_main.xml file and refer to the following code. Below is the code for the activity_main.xml file.


<?xml version="1.0" encoding="utf-8"?>
    <!--heading text view-->
        android:text="IFSC Code Validator"
        android:textSize="30sp" />
    <!-- edit text for entering our IFSC code
         we are specifying input type as number
         and we are also mentioning our input type
         as textcapCharacters because IFSC code is
         having all capital characters-->
        android:hint="Enter IFSC code"
        android:textAllCaps="true" />
    <!--button to get the data from IFSC code-->
        android:text="Get Bank Details"
        android:textAllCaps="false" />
    <!--text view to display the
        data received from IFSC code-->
        android:textSize="15sp" />

Step 4: Working with the file

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


import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONException;
import org.json.JSONObject;
public class MainActivity extends AppCompatActivity {
    // creating variables for edit text
    // and our text views.
    private EditText ifscCodeEdt;
    private TextView bankDetailsTV;
    // creating a variable for
    // our ifsc code string.
    String ifscCode;
    // creating a variable for request queue.
    private RequestQueue mRequestQueue;
    protected void onCreate(Bundle savedInstanceState) {
        // initializing our variables.
        ifscCodeEdt = findViewById(;
        Button getBankDetailsBtn = findViewById(;
        bankDetailsTV = findViewById(;
        // initializing our request queue variable with request queue
        // and passing our context to it.
        mRequestQueue = Volley.newRequestQueue(MainActivity.this);
        // initializing on click listener for our button.
        getBankDetailsBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // getting string  from edittext.
                ifscCode = ifscCodeEdt.getText().toString();
                // validating if the edit text
                // is empty or not.
                if (TextUtils.isEmpty(ifscCode)) {
                    // displaying a toast message if the text field is empty
                    Toast.makeText(MainActivity.this, "Please enter valid IFSC code", Toast.LENGTH_SHORT).show();
                } else {
                    // calling a method to display
                    // our ifsc code details.
    private void getDataFromIFSCCode(String ifscCode) {
        // clearing our cache of request queue.
        // below is the url from where we will be getting
        // our response in the json format.
        String url = "" + ifscCode;
        // below line is use to initialize our request queue.
        RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
        // creating a json object request for our API.
        JsonObjectRequest objectRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
            public void onResponse(JSONObject response) {
                // this method is used to get
                // the response from the API.
                try {
                    if (response.getString("status").equals("failed")) {
                        // checking if the response is not loaded and
                        // status for the repose is fail.
                        // if response status is failure we are displaying
                        // an invalid IFSC code in our text view.
                        bankDetailsTV.setText("Invalid IFSC Code");
                    } else {
                        // if the status is successful we are
                        // extracting data from JSON file
                        JSONObject dataObj = response.getJSONObject("data");
                        String state = dataObj.optString("STATE");
                        String bankName = dataObj.optString("BANK");
                        String branch = dataObj.optString("BRANCH");
                        String address = dataObj.optString("ADDRESS");
                        String contact = dataObj.optString("CONTACT");
                        String micrcode = dataObj.optString("MICRCODE");
                        String city = dataObj.optString("CITY");
                        // after extracting this data we are displaying
                        // that data in our text view.
                        bankDetailsTV.setText("Bank Name : " + bankName + "\nBranch : " + branch + "\nAddress : " + address + "\nMICR Code : " + micrcode + "\nCity : " + city + "\nState : " + state + "\nContact : " + contact);
                } catch (JSONException e) {
                    // if we get any error while loading data
                    // we are setting our text as invalid IFSC code.
                    bankDetailsTV.setText("Invalid IFSC Code");
        }, new Response.ErrorListener() {
            public void onErrorResponse(VolleyError error) {
                // if we get any error while loading json
                // data we are setting our text to invalid IFSC code.
                bankDetailsTV.setText("Invalid IFSC Code");
        // below line is use for adding object
        // request to our request queue.

Step 5: Add permission for the internet in the Manifest file 

Navigate to the app > AndroidManifest.xml file and add the below permissions to it. 


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

After adding this permission. Run your project and see the output on the below screen.  


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads