how do you get the phone's MCC and MNC in Android?

前端 未结 7 1057
感情败类
感情败类 2020-12-04 11:18

The only way I\'ve found of retrieving MCC and MNC is by overriding an activity\'s onConfigurationChanged method, as such:

public void onConfigurationChanged         


        
7条回答
  •  不知归路
    2020-12-04 12:15

    The TelephonyManager has a method to return the MCC+MNC as a String (getNetworkOperator()) which will do you what you want. You can get access it via:

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        TelephonyManager tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        String networkOperator = tel.getNetworkOperator();
    
        if (!TextUtils.isEmpty(networkOperator)) {
            int mcc = Integer.parseInt(networkOperator.substring(0, 3));
            int mnc = Integer.parseInt(networkOperator.substring(3));
        }
    }
    

提交回复
热议问题