设备语言为Deutche时无法获取国家/地区代码

时间:2018-07-17 06:26:02

标签: android

public String getCountryCode(String countryName, String language) {
    String[] isoCountryCodes = Locale.getISOCountries();
    for (String code : isoCountryCodes) {
        Locale locale = new Locale("de", code);
        Log.d(TAG, "getCountryCode: " + locale.getDisplayCountry() + " " + code);
        if (countryName.equalsIgnoreCase(locale.getDisplayCountry())) {
            return code;
        }
    }
    return "";
}
  

国家代码返回空。我该怎么解决?

0 个答案:

没有答案