localization - How to keep currency (keeping it localized) independent from system locale on android app? -


i've been researching solution issue while , not find proper solution. closest i've got this entry stackoverflow. since asked 4 years ago (and not issue although solve problem), 'll ask again see if there better workaround.

context: want release android app in several countries. available in spain. i've read android developers documentation localization. pretty clear dynamic localized information on code should based on "system locale" when presenting user.

problem: problem comes when user changes language on settings manually , want display price (generated app) bases it's currency on system locale preference. example lets live in spain , set device language & input/language english(united states). when app shows prices in dollars ($) want keep showing eur (€) since i'm in spain. how achieve this?

this mi actual code showing "localized" price user based on system locale:

    locale currentlocale = locale.getdefault();     priceformat = numberformat.getinstance(currentlocale);     localcurrency = currency.getinstance(current);     //...      //doublevaluecost independent currency want add proper currency symbol     costtextview.settext(priceformat.format(doublevaluecost) + " " + localcurrency.getsymbol()); 

this code add currency symbol system locale selected user on preferences , not actual currency symbol of country device is.

any advice welcomed. in advance.

after research decided use telephonymanager simcountryiso localize currency in concrete scenario mention in problem. not sure if best solution solve proble best option i've found. code currency need:

        string countryiso = telephonymanager.getsimcountryiso();         localcurrency = currency.getinstance(new locale(countryiso,countryiso));         //doublevaluecost independent currency want add proper currency symbol ...         costtextview.settext(priceformat.format(doublevaluecost) + " " + localcurrency.getsymbol()); 

if comes better solution, glad hear. thanks


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -