开发者

Get country based on GSM/UMTS network

I need to detect the MCC of the country in which the GSM/UMTS wireless modem is currently开发者_运维问答 now.


  1. Based on GSM networks

    You need to use getSimCountryIso() and getNetworkCountryIso() from the TelephonyManager

    Returns the ISO country code equivalent for the SIM provider's country code.

  2. Based on WIFI you use a Ip to Country database

  3. You have also the option to use the Geocoder class based on the location


First get the MCC/MNC:

TelephonyManager tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String networkOperator = tel.getNetworkOperator();

if (networkOperator != null) {
    int mcc = Integer.parseInt(networkOperator.substring(0, 3));
    int mnc = Integer.parseInt(networkOperator.substring(3));
}

Then, based on that, you can get the number corresponding to the selected MCC. There are plenty of lists on the internet, for example this one on Wikipedia

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜