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 ?
123 key in the lower-left corner of the keyboard. In the second row of numbers and symbols, press and hold your finger on the dollar-sign key. Above your finger, a box will pop up showing several currency symbols; these include the peso, the euro, the cent sign, the pound sterling and the yen.
The getSymbol() method is used to get the symbol of invoking currency for the default locale.
public final Map<String, String> CURRENCIES= new HashMap<String, String>(){ { put("EUR","€"); put("USD","$"); ... } }; Save this answer. Show activity on this post. You can simply use this code to get the currency symbol and different currency formats.
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();
}
}
get locale of device and then check http://www.avajava.com/tutorials/lessons/how-do-i-display-the-currency-for-a-locale.html
Locale current = getResources().getConfiguration().locale;
Log.i("locale", Currency.getInstance(current).getCurrencyCode());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With