Get country name from country code

依然范特西╮ 提交于 2019-12-21 03:13:10

问题


I'd need to get the full country name from the country code. For example for Netherlands, I'd need the Netherlands from the country code NL.

I thought I could do that with Locale like:

Locale loc = new Locale("NL");
loc.getCountry();

but loc.getCountry(); is empty.

Any idea about how to do this, please? Thanks in advance!


回答1:


try like this

Locale loc = new Locale("","NL");
loc.getDisplayCountry();

Hope this will help out.




回答2:


This should work:

Locale l = new Locale("", "NL");
String country = l.getDisplayCountry();

The first parameter of Locale is the language, which is not useful in your case.




回答3:


Try to use the other constructor

Locale loc = new Locale("NL", "The Netherlands");

Locale There does not appear to be a predefined Locale for The Netherlands




回答4:


for a full solution TelephonyManager (from this solution):

TelephonyManager teleMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String localeCountry = teleMgr.getNetworkCountryIso();
if (localeCountry != null) {
    Locale loc = new Locale("",localeCountry);
    Log.d(TAG, "User is from " + loc);
}


来源:https://stackoverflow.com/questions/14275868/get-country-name-from-country-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!