[英]How to get currency according to country code in Android?
在下面的代码中,我可以获得国家代码(2 alpha)。 是否可以根据国家代码获得货币? 如果是,请告诉我怎么做? 我不想为此应用添加任何运行时权限。
final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
final String simCountry = tm.getSimCountryIso();
if (simCountry != null && simCountry.length() == 2) { // SIM country code is available
String country_code = simCountry.toLowerCase(Locale.US);
//return result - "in". (for India)
//here I want to get the currency according to the country code
}
喜欢:
final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
final String simCountry = tm.getSimCountryIso();
if (simCountry != null && simCountry.length() == 2) {
String country_code = simCountry.toLowerCase(Locale.US);
Currency.getInstance(new Locale("", country_code)).getCurrencyCode()
}
// Currency.getInstance(new Locale("", "us")).getCurrencyCode() -- This Return USD
// Currency.getInstance(new Locale("", "in")).getCurrencyCode() -- This Retrun INR
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.