从国家/地区代码获取国家名称

时间:2022-08-29 07:30:18

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.

我需要从国家/地区代码中获取完整的国家/地区名称。例如荷兰,我需要荷兰国家代码NL。

I thought I could do that with Locale like:

我以为我可以用Locale这样做:

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

but loc.getCountry(); is empty.

但是loc.getCountry();是空的。

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

请问有关怎么做的想法?提前致谢!

5 个解决方案

#1


72  

try like this

试试这样

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

Hope this will help out.

希望这会有所帮助。

#2


22  

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.

Locale的第一个参数是语言,在您的情况下无用。

#3


0  

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


0  

for a full solution TelephonyManager (from this solution):

对于完整的解决方案TelephonyManager(来自此解决方案):

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);
}

#5


-3  

as @ShreyaShah pointed out, the solution is using loc.getDisplayCountry()

正如@ShreyaShah指出的那样,解决方案是使用loc.getDisplayCountry()

#1


72  

try like this

试试这样

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

Hope this will help out.

希望这会有所帮助。

#2


22  

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.

Locale的第一个参数是语言,在您的情况下无用。

#3


0  

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


0  

for a full solution TelephonyManager (from this solution):

对于完整的解决方案TelephonyManager(来自此解决方案):

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);
}

#5


-3  

as @ShreyaShah pointed out, the solution is using loc.getDisplayCountry()

正如@ShreyaShah指出的那样,解决方案是使用loc.getDisplayCountry()