Where Am I? - Get Country

Where am I? - Get country

This will get the country code set for the phone (phones language, NOT user location):

 String locale = context.getResources().getConfiguration().locale.getCountry(); 

can also replace getCountry() with getISO3Country() to get a 3 letter ISO code for the country. This will get the country name:

 String locale = context.getResources().getConfiguration().locale.getDisplayCountry();

This seems easier than the other methods and rely upon the localisation settings on the phone, so if a US user is abroad they probably still want Fahrenheit and this will work :)

Editors note: This solution has nothing to do with the location of the phone. It is constant. When you travel to Germany locale will NOT change. In short: locale != location.

How can I get a user's country location?

You can check if user is in the EU by requesting the URL http://adservice.google.com/getconfig/pubvendors. It gives you an answer like this:

{"is_request_in_eea_or_unknown":true}

Somewhere I've read that it is the way the Android consent SDK works.

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

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

String locale = context.getResources().getConfiguration().locale.getCountry();

Get current country in Android - traveling

For #2- its a country code. This is an ISO standard. It will be the 2 letter code. The list can be found here http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2

How to determine an Android device's current country location regardless of user location settings?

Your approach of third party ip location api seems right to currently. May be This would help you

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

http://ip-api.com/json

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

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.

How to get Country Code like +91, +1, +65 from the country name like IN, US, SG in Android?

You can get country ID but not code like +91,+1 and so on

TelephonyManager manager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
CountryID= manager.getSimCountryIso().toUpperCase();

You can prepare your own database for that and manually you need to search from database and then handle such kind of operations

check here for this kind of data



Related Topics



Leave a reply



Submit