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

后端 未结 9 1413
忘了有多久
忘了有多久 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:11

    I think the IP address is the best way because it will give you the country where the phone is at the moment.

    If you do it by

    Locale.getDefault().getCountry();
    

    you get the country where the user select the country, so you can have selected England, and you can be in Spain and maybe you need to know where he/she is at the moment.

    Example: imagine that your app can buy something only in England. The user is from Spain, but he/she is on holidays in England and he/she wants to buy your product ... if you use

    Locale.getDefault().getCountry();
    

    that user won't be able to buy your product, so the IP address is the best way I think.

提交回复
热议问题