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

后端 未结 9 1426
忘了有多久
忘了有多久 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 17:59

    Use:

    TelephonyManager tm = (TelephonyManager)getSystemService(getApplicationContext().TELEPHONY_SERVICE);
    String countryCode = tm.getNetworkCountryIso();
    

    It is better than getSimCountryIso because getSimCountryIso depends on the operator to burn the country ISO into the SIM and it also supports CDMA networks.

提交回复
热议问题