Where am I? - Get country
android, geolocation
Solution
This will get the country code set for the phone (phones language, NOT user location):
String locale = context.getResources().getConfiguration().locale.getCountry();
can also replace getCountry() with getISO3Country() to get a 3 letter ISO code for the country. This will get the country name:
String locale = context.getResources().getConfiguration().locale.getDisplayCountry();
This seems easier than the other methods and rely upon the localisation settings on the phone, so if a US user is abroad they probably still want Fahrenheit and this will work :)
Editors note: This solution has nothing to do with the location of the phone. It is constant. When you travel to Germany locale will NOT change. In short: locale != location.
Problem
An android mobile actually does know quite well where it is - but is there a way of retrieving the country by something like a country code? No need of knowing the exact GPS position - the country is sufficient I first thought of using the time zone, but actually I need more information than that since it makes a difference if the location is New York or Lima. The background of the question: I have an application that uses temperature values, and I'd like to set the default unit either to Celsius or Fahrenheit, depending on whether the location is US or outside