Android Can I get the currency code of the country where the user and device are located?

Is it possible to get the currency code of the country where the user and device are located. I want to set the country code of the user's current country as the default country. Do we have a solution for this in android?

+3


source to share


2 answers


Since this piece of code might be helpful 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();
    }
}

      

+15


source


get device locale 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());

      

+3


source







All Articles