0

I am new in Java Android.

I would like to get the name of country (String) using country code in Locale (Ref. ISO 3166-1 numeric)

Tried to do something like that (where [...].getCountry() return int 826):

Locale countryName = new Locale("", String.valueOf(profile.getPersonnalInformation().getAddress().getCountry())); 

and get the name of country using this: countryName.getDisplayCountry()

It should normally return me "United Kingdom" but unfortunately I have 826.

How can I do that ?

In advance thank you for your help,

O. Boujaouane
  • 285
  • 5
  • 18
  • @MehdiKhademloo thank you but I try to do it with int number and not string like in your example. I already tried to cast my int in String and use it but it doesn't work so your link doesn't help me. I already read it before you post it. – O. Boujaouane Jun 29 '17 at 09:30
  • This is important because when you read contacts in a phone you get a number(2 digit) but when you libphonenumber you feed it an alpha-2.. – DragonFire Feb 05 '19 at 09:46

2 Answers2

5

Now an implementation of country code (ISO 3166-1 alpha-2/alpha-3/numeric) list as Java enum is available at GitHub under Apache License version 2.0.

Example:

int c_code=profile.getPersonnalInformation().getAddress().getCountry());// 392

CountryCode cc = CountryCode.getByCode(c_code);

String country_name=cc.getName();              // "Japan"

Gradle

dependencies {

  compile 'com.neovisionaries:nv-i18n:1.20'

}

Github

https://github.com/TakahikoKawasaki/nv-i18n

Jitesh Prajapati
  • 2,533
  • 4
  • 29
  • 51
Adnan Maqbool
  • 452
  • 3
  • 10
1

you have to get the countricode string (2 or 3 letters) to use it. There is a opensource lib on github that will do it for you. see Is there an open source java enum of ISO 3166-1 country codes or take just the enum from https://subversivebytes.wordpress.com/2013/10/07/java-iso-3166-java-enum/

Fusselchen
  • 382
  • 1
  • 4
  • 12