Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve the CountryCode / ISO?

Our intention is to filter the content based on location without requesting Location permission from the Android device,

In-order to meet this requirement, we have tried the following options and still its not reliable

  1. Telephony Manager

it wont work without a Sim card, again say if the user from USA travels india now the below snippets returns US not India

var telephonyManager = context?.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
val countryCodeValue = telephonyManager.networkCountryIso
  1. Locale

Locale returns US or UK by default even if they are in India, usually user's Locale would be in English by default

 Locale.getDefault().getCountry()
  1. GPS

We doesn't want the Location permission to be requested

  1. Retrieving the Country details form the logged-in Google account

Reply from Google - They dont have any dedicated API to retrieve countryCode of an user Note: iOS has a dedicated API which tell the CountryCode of the user, but Android doesn't

  1. IP address

We tried to get the IP of the Android device (from several IP fusion websites), there are following two cases

  • User connected to WiFi - we are able to get the countryCode (WIFI IP : 64.134.234.17)
  • User connected to Mobile Data - we are getting the wrong countryCode even we are in USA, it says that IP is from JAPAN (MOBILE NETWORK IP: 210.253.218.106)

Note: Even Netflix determine the country during the launch, without requesting the Location permission

like image 612
User2364902 Avatar asked Jun 14 '18 07:06

User2364902


People also ask

How do I get a country phone prefix ISO?

TELEPHONY_SERVICE); String countryCode = tm. getSimCountryIso();

Why is the ISO country code for UK GB?

Though GB is the United Kingdom's ISO 3166-1 alpha-2 code, UK is exceptionally reserved for the United Kingdom on the request of the country. Its main usage is the . uk internet ccTLD and, on 28 September 2021, UK replaced GB as the official country code on car registration plates.

What's my country code?

United States Country Code 1 Country Code US.


1 Answers

I think you have only two possibilities...or ask permission...or without asking permission you have to ask the user to insert an address (also only the city) and retrive the country code by mean of Google Geocoding Service

like image 117
giudigior Avatar answered Sep 29 '22 12:09

giudigior