Skip to content

Abhay-cloud/Indian-Pincodes-Library

Repository files navigation

Indian-Pincodes-Library

Implementation

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2. Add the dependency

dependencies {
  implementation 'com.github.Abhay-cloud:Indian-Pincodes-Library:0.4.0'
}

Usage

isValidPincode(Context context, String pincode)

// Example
   Boolean isValid = IndianPincodes.isValidPincode(this, "411002");

It will return true if given pincode exists.

getPincodeByCity(Context context, String City)

// Example
   JSONObject OBJ = IndianPincodes.getPincodeByCity(this, "Pune");

        try {
            JSONArray arr = OBJ.getJSONArray("Result");
            for (int i = 0;i<arr.length();i++){
                JSONObject obj2 = arr.getJSONObject(i);

                Log.d("myapp", "PostOffice: " + obj2.getString("PostOfficeName") + " Pincode " + obj2.getString("pincode"));
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

It will return a JSON Object which will contain "Result" JSON Array that array will contain bunch (maybe none or one too) of Json objects. Then you can get information by using obj2.getString("PostOfficeName"), obj2.getString("pincode"), etc.

getStatePincodes(Context context, String State)

// Example
    JSONObject OBJ = IndianPincodes.getStatePincodes(this, "Maharashtra");

      try {
          JSONArray arr = OBJ.getJSONArray("Result");
          for (int i = 0;i<arr.length();i++){
              JSONObject obj2 = arr.getJSONObject(i);

              Log.d("myapp", "City: " + obj2.getString("City") + " PostOffice: " + obj2.getString("PostOfficeName") + " Pincode " + obj2.getString("pincode"));
          }

      } catch (JSONException e) {
          e.printStackTrace();
      }

It will return a JSON Object which will contain "Result" JSON Array that array will contain bunch (maybe none or one too) of Json objects. Then you can get information by using obj2.getString("City"), obj2.getString("pincode"), etc.

getDistrictPincodes(Context context, String District)

  // Example
      JSONObject OBJ = IndianPincodes.getDistrictPincodes(this, "Pune");

        try {
            JSONArray arr = OBJ.getJSONArray("Result");
            for (int i = 0;i<arr.length();i++){
                JSONObject obj2 = arr.getJSONObject(i);

                Log.d("myapp", "City: " + obj2.getString("City") + " PostOffice: " + obj2.getString("PostOfficeName") + " Pincode " + obj2.getString("pincode"));
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

It will return a JSON Object which will contain "Result" JSON Array that array will contain bunch (maybe none or one too) of Json objects. Then you can get information by using obj2.getString("City"), obj2.getString("pincode"), etc.

getInfoByPincode(Context context, String pincode)

  // Example
      JSONObject OBJ = IndianPincodes.getInfoByPincode(this, "411002");

        try {
            JSONArray arr = OBJ.getJSONArray("Result");
            for (int i = 0;i<arr.length();i++){
                JSONObject obj2 = arr.getJSONObject(i);

                Log.d("myapp", "City: " + obj2.getString("City") + " PostOffice: " + obj2.getString("PostOfficeName") + " Pincode " + obj2.getString("pincode")
                   + " District: " + obj2.getString("District") + " State: " + obj2.getString("State"));
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

It will return a JSON Object which will contain "Result" JSON Array that array will contain bunch (maybe none or one too) of Json objects. Then you can get information by using obj2.getString("City"), obj2.getString("pincode"), etc.

Connect with me

If you have any difficulty then just message me on Instagram or Telegram.

Made with ❤️ by Abhay