繁体   English   中英

如何根据Android中的国家代码获取货币?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM