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

后端 未结 9 1416
忘了有多久
忘了有多久 2020-12-04 17:32

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 wa

9条回答
  •  天命终不由人
    2020-12-04 18:14

    It's very hard to find the country without GPS and Google Services (China). TelephonyManager won't work if there isn't any SIM card in your phone.

    And Locale won't work if a user in China set his/her language as English (the country you will be getting will be US or UK).

    If your app requires an Internet connection then there is an option. You could use this API called ip-api. Please go through their documentation first if you are planing to use this.

    There are other APIs like this freegeoip API.

提交回复
热议问题