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.
setText(locale. getLanguage()); Here you use locale. getLanguage() to get the Android Locale country code of the language that is currently being used in your Android device.
The 7th and 8th number of the IMEI represents its country of origin or the country in which the phone was manufactured or assembled. In the above Example we can see that the 7th and 8th Digits are – 04. This is How we can know the Country of Origin of the Phone.
A Locale object represents a specific geographical, political, or cultural region. An operation that requires a Locale to perform its task is called locale-sensitive and uses the Locale to tailor information for the user.
You shouldn't be passing anything in to getCountry()
. Remove Locale.getDefault()
:
String locale = context.getResources().getConfiguration().locale.getCountry();
You can simply use this code,
TelephonyManager tm = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE); String countryCodeValue = tm.getNetworkCountryIso();
This will return 'US' if your current connected network is in the United States. This works without a SIM card even.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With