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 or country name?
There isn't any need to know the exact GPS position - the country code or name is sufficient, and I am using this code:
String locale = context.getResources().getConfiguration().locale.getCountry(Locale.getDefault());
System.out.println("country = "+locale);
It gives me the code "US", but my device kept in India. Is there a way to find the device's current country code without using GPS or a network provider?
Because I am using a tablet.
You shouldn't be passing anything in to getCountry()
. Remove Locale.getDefault()
:
String locale = context.getResources().getConfiguration().locale.getCountry();