Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get my Android device country code without using GPS?

Tags:

android

locale

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.

like image 755
Vikas Goyal Avatar asked Jul 02 '12 12:07

Vikas Goyal


People also ask

How do I find the country code of my Android phone?

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.

How do I know what country my device is from?

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.

What is locale Android?

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.


2 Answers

You shouldn't be passing anything in to getCountry(). Remove Locale.getDefault():

String locale = context.getResources().getConfiguration().locale.getCountry(); 
like image 177
Rawkode Avatar answered Sep 21 '22 03:09

Rawkode


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.

like image 38
Kishath Avatar answered Sep 22 '22 03:09

Kishath