How can I find out the currency of the country in which the user of the Android application is currently located? It is assumed that the user travels frequently and changes the country. Prompt any service with open API.
1 answer
Solution from the end: https://developer.android.com/reference/java/util/Currency.html A class that gives a currency code, symbol, etc. Made from locale:
Currency currency = Currency.getInstance(locale); Locale can be made from the coordinates:
Geocoder geocoder = new Geocoder(ctx, Locale.getDefault()); List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1); if (addresses.size() > 0) { Address address = addresses.get(0); regionCode = address.getCountryCode(); } Article from the original source: https://developer.android.com/training/location/display-address.html
The regionCode must contain a 2-character code, for example, 'RU', 'US', 'DE'.
From this code we make the locale:
Locale whereMI = new Locale(regionCode); My apologies for the incoherence of the code, kicked up from different projects in parts.
P.S. Alternatively, instead of GPS, you can use ip-api.com/json to get the country code. With known reservations of course.
- The main thing that suggested where to look) Thank you) - JJoe
|