0

我需要根据用户为我的 android 应用程序输入的国家/地区访问 ISO3 国家/地区代码。有没有可能直接访问它而不是将其存储在数组中的方法。

4

1 回答 1

2

您可以使用电话管理器或使用 IP 地址获取当前的 ISO2 国家代码。然后使用Locale获取 ISO3 国家代码。

这是示例:

  TelephonyManager tm = (TelephonyManager)getSystemService(getApplicationContext().TELEPHONY_SERVICE);
  String countryCode = tm.getNetworkCountryIso();
  String currentISO3CountryCode = new Locale("", countryCode).getISO3Country();

另外这里是获取所有国家/地区的 ISO3 代码的示例:

for (String country : Locale.getISOCountries()) {
        Locale locale = new Locale("", country);
        Log.v(TAG, "ISO3 country code: " + locale.getISO3Country().toUpperCase());
    }
于 2016-08-17T12:54:54.130 回答