How to programmatically determine which country an Android device is currently located without using GPS?

When my application starts, I want to determine the current name of the country of location and do some things for that name of a specific country, I can easily do this using a geocoder, gps. But I want to get it from Locale or if something else is available.

+3
source share
3 answers

I do not know if the Android API allows you to check the provider code of the corresponding GSM network. If possible, you can use this code, for example, for this list: http://www.techgsm.com/page/gsm-provider-codes/network-provider-identify-codes.html to find out in which country is a mobile phone.

+5

http://ip-api.com/json, json. json . IP-, IP- .

Docs http://ip-api.com/docs/api:json , .

, .

{
"as": "AS55410 C48 Okhla Industrial Estate, New Delhi-110020",
"city": "Kochi",
"country": "India",
"countryCode": "IN",
"isp": "Vodafone India",
"lat": 9.9667,
"lon": 76.2333,
"org": "Vodafone India",
"query": "123.63.81.162",
"region": "KL",
"regionName": "Kerala",
"status": "success",
"timezone": "Asia/Kolkata",
"zip": ""

}

+11

( ) Android. , .aidl, , . , - Country detectCountry();, android.location.Country(frameworks/base/location/java/android/location/Country.java AOSP). , , ( getSystemService ( "country_detector" )).

, :

shell@flounder:/ $ service call country_detector 1
Result: Parcel(
  0x00000000: 00000000 00000001 00000002 00530055 '............U.S.'
  0x00000010: 00000000 00000003 1d809dda 00000000 '................')

Serialization of objects is basically nothing more than a two-letter country code (here: USA), source (here, 3, implying that it was taken from Locale), and a timestamp (1d809dda ...), which really is important. You do not need to worry about serialization because the object is Parcelable.

+1
source

All Articles