Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Is it possible to get the currency code of the country, where the user and device is?

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 ?

like image 882
Droid_Dev Avatar asked Dec 01 '14 12:12

Droid_Dev


People also ask

How can I get currency code 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.

How can I get currency from locale?

The getSymbol() method is used to get the symbol of invoking currency for the default locale.

How do you make the currency symbol?

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.


2 Answers

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();
    }
}
like image 84
Fatti Khan Avatar answered Oct 12 '22 00:10

Fatti Khan


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());
like image 41
MohK Avatar answered Oct 11 '22 23:10

MohK