从国家代码 int 获取国家名称字符串

O. *_*ane 0 android locale country-codes

我是 Java Android 新手。

我想在区域设置中使用国家/地区代码(参考ISO 3166-1 数字)获取国家/地区名称(字符串)

试图做这样的事情(其中 [...].getCountry() 返回 int 826):

Locale countryName = new Locale("", String.valueOf(profile.getPersonnalInformation().getAddress().getCountry())); 
Run Code Online (Sandbox Code Playgroud)

并使用此获取国家/地区名称: countryName.getDisplayCountry()

它通常应该返回“英国”,但不幸的是我有 826。

我怎样才能做到这一点 ?

在此先感谢您的帮助,

小智 5

现在,国家代码 ( ISO 3166-1 alpha-2 / alpha-3 / numeric ) 列表作为 Java 枚举的实现可在 Apache 许可证版本 2.0 下在 GitHub 上获得。

例子:

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

CountryCode cc = CountryCode.getByCode(c_code);

String country_name=cc.getName();              // "Japan"
Run Code Online (Sandbox Code Playgroud)

摇篮

dependencies {

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

}
Run Code Online (Sandbox Code Playgroud)

GitHub

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