Android是否可以获取用户和设备所在国家/地区的货币代码? [英] Android Is it possible to get the currency code of the country, where the user and device is?
本文介绍了Android是否可以获取用户和设备所在国家/地区的货币代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以获取用户和设备所在国家/地区的货币代码。我想将用户当前国家/地区的国家/地区代码设置为默认国家/地区。我们在android中有这个解决方案吗?
Is it possible to get the currency code of the country, where the user and device is. i want to set the country code of the present country of the user as default country. Do we have a solution for this in android ?
推荐答案
因为这段代码可能对你有所帮助,
As this piece of code might be helpfull for you ,
public class CurrencyTest {
public static void main(String[] args) throws Exception {
Locale defaultLocale = Locale.getDefault();
displayCurrencyInfoForLocale(defaultLocale);
Locale swedishLocale = new Locale("sv", "SE");
displayCurrencyInfoForLocale(swedishLocale);
}
public static void displayCurrencyInfoForLocale(Locale locale) {
System.out.println("Locale: " + locale.getDisplayName());
Currency currency = Currency.getInstance(locale);
System.out.println("Currency Code: " + currency.getCurrencyCode());
System.out.println("Symbol: " + currency.getSymbol());
System.out.println("Default Fraction Digits: " + currency.getDefaultFractionDigits());
System.out.println();
}
}
这篇关于Android是否可以获取用户和设备所在国家/地区的货币代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文