get Telephony Mcc Mnc - Android android.telephony

Android examples for android.telephony:TelephonyManager

Description

get Telephony Mcc Mnc

Demo Code


import android.content.Context;
import android.content.res.Configuration;
import android.telephony.TelephonyManager;
import android.util.Log;

public class Main {
  private static final String TAG = "";

  public static String getMccMnc(final Context context) {
    final TelephonyManager tm = (TelephonyManager) context
        .getSystemService(Context.TELEPHONY_SERVICE);
    final int configMcc = context.getResources().getConfiguration().mcc;
    final int configMnc = context.getResources().getConfiguration().mnc;
    if (tm.getSimState() == TelephonyManager.SIM_STATE_READY) {
      Log.w(TAG, "Choosing MCC+MNC info from TelephonyManager.getSimOperator()");
      return tm.getSimOperator();
    } else if (tm.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) {
      Log.w(TAG,/*from w  ww  .  j  a v  a  2  s  .c om*/
          "Choosing MCC+MNC info from TelephonyManager.getNetworkOperator()");
      return tm.getNetworkOperator();
    } else if (configMcc != 0 && configMnc != 0) {
      Log.w(TAG, "Choosing MCC+MNC info from current context's Configuration");
      return String.format("%03d%d", configMcc,
          configMnc == Configuration.MNC_ZERO ? 0 : configMnc);
    } else {
      return null;
    }
  }
}

Related Tutorials