Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
W

worldCountryData

> 包管理
Open source

Android library for country flag, currency, and other country information

99 stars0 likes1 views
WebsiteGitHub

About

Android library for country flag, currency, and other country information

World Country Data, flags, currency and more - an open source android library for getting country flags and other country attributes


An Android library that contains 'all' the flags of the countries of the world This is to be used for android projects where the developer is interested in getting the flag of a particular country for any reason.

  • A flag is obtained as a drawable resource (int).
  • A flag can be set to an ImageView using XML
  • There is possibility to get all the countries and their flags by invoking just two methods.

System requirement

  • Android minSdkVersion = 15
  • Android targetSdkVersion = 33

Known Limitations

This library has been known to crash apps if you set shrinkResources true in your build settings. See step 2.3 below on how to deal with this!

This library will also result to a larger APK size of your app! It however gives you the advantage that it does not require any network calls


Usage

  1. Add JitPack in your repository build file build.gradle (Project appname)
groovy
allprojects {
    repositories {
        //...
        maven { url 'https://jitpack.io' }
    }
}

2.1 Add the dependency in your build.gradle (Module: app)

groovy
dependencies {
    //...
    implementation 'com.github.blongho:worldCountryData:$version'
}

Replace $version with vXXX for the most stable version you want to use see releases

Proguard rules

2.2 Add this in your proguard-rules.pro

groovy
-keep

class com

.blongho.** {
    *;
}
-keep

interface com

.blongho.**
#
If you
keep the line number information , uncomment this to
# hide the original source file name.
# -renamesourcefileattribute SourceFile
-keeppackagenames com.blongho.country_data
-keepclassmembers

class com

.blongho.country_data.* {
    public *;
}
-keep

class com

.blongho.country_data.R$ * {
    *;
}

2.3 In your build.gradle (Module: app)

groovy
android {
    ...

    buildTypes {
        release {
            minifyEnabled true
            //shrinkResources false // if you set this to true, the application will crash
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }

    }

    defaultConfig {
        vectorDrawables.useSupportLibrary = true
    }

    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }
    ...
}

  1. Build your project (and make sure gradle has successfully synced) Buid >> Clean Project, Build >> Rebuild Project

  2. Load all the flags of the world by calling. Do this once in the application context.

java
World.init(getApplicationContext()); // Initializes the libray and loads all data

This inititializes the data. All countries are read, and their flags loaded

  1. Get the flag of a country(dynamically)
  • You can get the flag of a country by using the two iso alpha2 or alpha3 or the country name or the numeric code.
…
  • You can hard-code the country flag if you know the alpha2 code of the country. Eg. to set the flag of Sweden, you could do
xml

 
  • In java code, you could statically do same as
java
// Set the image of an imageView
final ImageView swedishFlag=(ImageView)findViewById(R.id.flagImageView);
        swedishFlag.setImageResource(R.drawable.se);
  1. Get a Country with attributes like "id":4,"name":"Afghanistan","alpha2":"af","alpha3":"afg", flag:imageResource"
java
final Country afghanistan=World.getCountryFrom("af|afg|afghanistan|4|kabul");
// Log.d(TAG, afghanistan.toString()); 
  1. Get a list of all the countries with their identifiers
java
final List countries=World.getAllCountries();
// This list cannot be modified but you can get its contents
  1. Get list of countries from a continent
java
final List africanCounties=World.getCountriesFrom(Continent.AFRICA);
///final List filteredCountries = World.getCountriesFrom(Continent.[AFRICA|ASIA|EUROPE|OCEANA|SOUTH_AMERICA|NORTH_AMERICA])
// Continent is an enum that has all the continents of the world

NEW

  1. Get the list of languages spoken in a given country
java
final List languages=World.getLanguagesFrom("af|afg|afghanistan|4|kabul");
//or 
final Country afghanistan=World.getCountryFrom("af|afg|afghanistan|4|kabul");
final List languages=afghanistan.getLanguages();
// Returns comma separated list of country languages e.g [Swedish (sv-SE), Northern Sami (se), Southern Sami (sma), Finnish (fi-SE)]

Link to javadoc --> javadoc link

All the steps above are demonstrated in this project --> world country flag demo


| | |:--:| | Live retrieval of Country data |


Get this sample app in the playstore Data sources for the project

All country flags

Most of the flags came from flagpedia.net. This site does not contain all the countries in the world so some where downloaded from wikipedia after quering the country name

Countries and their iso alpha values

All country names were download from Geonames using a Python project written by Bernard Longho aka @blongho. Check it out Countries data by blongho

Getting different dimensions of the flags

Some guys from Egypt made some awesome App icon generator which generates android drawables as well as iOS images(if you want) in different dimensions. It is super fast and can do batch processing of images.


Contribution guidelines

Please feel free to add more flags or modify any thing that would make this library more useful. The various ways of contribution are specified in CONTRIBUTING.md


Sponsors

Contact

Feel free to contact me to discuss anything related to development in particular and life in general.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Javaandroidandroid-librarycontinentscountry-capitals

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category包管理
PricingOpen source

> Related tools

N
npm
Node.js 默认包管理器
P
pnpm
高效节省磁盘的 Node 包管理器
I
is-gif
Check if a Buffer/Uint8Array is a GIF image