Java 如何根据用户在Android中输入的国家访问或获取ISO3国家代码
我需要根据用户为我的android应用程序输入的国家/地区访问ISO3国家/地区代码。是否有任何可能的方法直接访问它而不是将其存储在阵列中。您可以使用电话管理器或IP地址获取当前的ISO2国家/地区代码。然后使用语言环境获取ISO3国家代码 以下是示例:Java 如何根据用户在Android中输入的国家访问或获取ISO3国家代码,java,android,locale,country-codes,mobile-country-code,Java,Android,Locale,Country Codes,Mobile Country Code,我需要根据用户为我的android应用程序输入的国家/地区访问ISO3国家/地区代码。是否有任何可能的方法直接访问它而不是将其存储在阵列中。您可以使用电话管理器或IP地址获取当前的ISO2国家/地区代码。然后使用语言环境获取ISO3国家代码 以下是示例: TelephonyManager tm = (TelephonyManager)getSystemService(getApplicationContext().TELEPHONY_SERVICE); String countryCod
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());
}