Search code examples
androidlocationcountry-codes

How can I get the country (or its ISO code)?


What is the best way to get the country code?

As of now, I know two ways. One is to get by TelephonyManager and another by Locale. Which is another best and unique way to find the country code on Android? To be more specific if TelephonyManager is not available in device e.g. its a tablet with no telephony. We can not relay on Locale as user could be in different country.


Solution

  • I solved it by IP Address. You can get the IP address of your phone. If you are using Wi-Fi then it will be the IP address of the Wi-Fi hotspot or IP address of your mobile service provider server, so from that IP address you can send to a web service or something to track the country of that IP address.

    There are some sources (database) available if Internet which provides the country of IP address.

    Here is the example http://whatismyipaddress.com/ip-lookup.