Java Code Examples for android.telephony.TelephonyManager#getSimOperator()

The following examples show how to use android.telephony.TelephonyManager#getSimOperator() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
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.i(TAG, "Choosing MCC+MNC info from TelephonyManager.getSimOperator()");
    return tm.getSimOperator();
  } else if (tm.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) {
    Log.i(TAG, "Choosing MCC+MNC info from TelephonyManager.getNetworkOperator()");
    return tm.getNetworkOperator();
  } else if (configMcc != 0 && configMnc != 0) {
    Log.i(TAG, "Choosing MCC+MNC info from current context's Configuration");
    return String.format(Locale.ROOT, "%03d%d",
        configMcc,
        configMnc == Configuration.MNC_ZERO ? 0 : configMnc);
  } else {
    return null;
  }
}
 
Example 2
Source Project: Android-utils   File: DeviceUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Return the phone status.
 * <p>Must hold
 * {@code <uses-permission android:name="android.permission.READ_PHONE_STATE" />}</p>
 *
 * @return DeviceId = 99000311726612<br>
 * DeviceSoftwareVersion = 00<br>
 * Line1Number =<br>
 * NetworkCountryIso = cn<br>
 * NetworkOperator = 46003<br>
 * NetworkOperatorName = 中国电信<br>
 * NetworkType = 6<br>
 * PhoneType = 2<br>
 * SimCountryIso = cn<br>
 * SimOperator = 46003<br>
 * SimOperatorName = 中国电信<br>
 * SimSerialNumber = 89860315045710604022<br>
 * SimState = 5<br>
 * SubscriberId(IMSI) = 460030419724900<br>
 * VoiceMailNumber = *86<br>
 */
@SuppressLint("HardwareIds")
@RequiresPermission(READ_PHONE_STATE)
public static String getPhoneStatus() {
    TelephonyManager tm =
            (TelephonyManager) UtilsApp.getApp().getSystemService(Context.TELEPHONY_SERVICE);
    String str = "";
    //noinspection ConstantConditions
    str += "DeviceId(IMEI) = " + tm.getDeviceId() + "\n";
    str += "DeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion() + "\n";
    str += "Line1Number = " + tm.getLine1Number() + "\n";
    str += "NetworkCountryIso = " + tm.getNetworkCountryIso() + "\n";
    str += "NetworkOperator = " + tm.getNetworkOperator() + "\n";
    str += "NetworkOperatorName = " + tm.getNetworkOperatorName() + "\n";
    str += "NetworkType = " + tm.getNetworkType() + "\n";
    str += "PhoneType = " + tm.getPhoneType() + "\n";
    str += "SimCountryIso = " + tm.getSimCountryIso() + "\n";
    str += "SimOperator = " + tm.getSimOperator() + "\n";
    str += "SimOperatorName = " + tm.getSimOperatorName() + "\n";
    str += "SimSerialNumber = " + tm.getSimSerialNumber() + "\n";
    str += "SimState = " + tm.getSimState() + "\n";
    str += "SubscriberId(IMSI) = " + tm.getSubscriberId() + "\n";
    str += "VoiceMailNumber = " + tm.getVoiceMailNumber();
    return str;
}
 
Example 3
Source Project: Common   File: PhoneUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Return the sim operator using mnc.
 *
 * @return the sim operator
 */
public static String getSimOperatorByMnc(@NonNull Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
    String operator = tm.getSimOperator();
    if (operator == null) return "";
    switch (operator) {
        case "46000":
        case "46002":
        case "46007":
        case "46020":
            return "中国移动";
        case "46001":
        case "46006":
        case "46009":
            return "中国联通";
        case "46003":
        case "46005":
        case "46011":
            return "中国电信";
        default:
            return operator;
    }
}
 
Example 4
private void updateTile() {
    TelephonyManager manager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    String code = manager.getSimOperator();
    String country = manager.getSimCountryIso();

    SharedPreferences preferences = PropUtil.getProtecredSharedPreferences(this);

    Tile tile = getQsTile();
    tile.setLabel(String.format("%s %s", code, country));
    if (preferences.getBoolean(PropUtil.PREFERENCE_ENABLED, PropUtil.PREFERENCE_ENABLED_DEFAULT)) {
        tile.setState(Tile.STATE_ACTIVE);
    }
    else {
        tile.setState(Tile.STATE_INACTIVE);
    }
    tile.updateTile();
}
 
Example 5
Source Project: Android-UtilCode   File: PhoneUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 获取Sim卡运营商名称
 * <p>中国移动、如中国联通、中国电信</p>
 *
 * @return 移动网络运营商名称
 */
public static String getSimOperatorByMnc() {
    TelephonyManager tm = (TelephonyManager) Utils.getContext().getSystemService(Context.TELEPHONY_SERVICE);
    String operator = tm != null ? tm.getSimOperator() : null;
    if (operator == null) return null;
    switch (operator) {
        case "46000":
        case "46002":
        case "46007":
            return "中国移动";
        case "46001":
            return "中国联通";
        case "46003":
            return "中国电信";
        default:
            return operator;
    }
}
 
Example 6
Source Project: AndroidHttpCapture   File: LDNetUtil.java    License: MIT License 6 votes vote down vote up
public static String getMobileOperator(Context context) {
  TelephonyManager telManager = (TelephonyManager) context
      .getSystemService(Context.TELEPHONY_SERVICE);
  if(telManager==null)
  	return "未知运营商";
  String operator = telManager.getSimOperator();
  if (operator != null) {
    if (operator.equals("46000") || operator.equals("46002")
        || operator.equals("46007")) {
      return "中国移动";
    } else if (operator.equals("46001")) {
      return "中国联通";
    } else if (operator.equals("46003")) {
      return "中国电信";
    }
  }
  return "未知运营商";
}
 
Example 7
Source Project: RxTools-master   File: RxDeviceTool.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 获取手机状态信息
 * <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_PHONE_STATE"/>}</p>
 *
 * @param context 上下文
 * @return DeviceId(IMEI) = 99000311726612<br>
 * DeviceSoftwareVersion = 00<br>
 * Line1Number =<br>
 * NetworkCountryIso = cn<br>
 * NetworkOperator = 46003<br>
 * NetworkOperatorName = 中国电信<br>
 * NetworkType = 6<br>
 * honeType = 2<br>
 * SimCountryIso = cn<br>
 * SimOperator = 46003<br>
 * SimOperatorName = 中国电信<br>
 * SimSerialNumber = 89860315045710604022<br>
 * SimState = 5<br>
 * SubscriberId(IMSI) = 460030419724900<br>
 * VoiceMailNumber = *86<br>
 */
public static String getPhoneStatus(Context context) {
    TelephonyManager tm = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    String str = "";
    str += "DeviceId(IMEI) = " + tm.getDeviceId() + "\n";
    str += "DeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion() + "\n";
    str += "Line1Number = " + tm.getLine1Number() + "\n";
    str += "NetworkCountryIso = " + tm.getNetworkCountryIso() + "\n";
    str += "NetworkOperator = " + tm.getNetworkOperator() + "\n";
    str += "NetworkOperatorName = " + tm.getNetworkOperatorName() + "\n";
    str += "NetworkType = " + tm.getNetworkType() + "\n";
    str += "honeType = " + tm.getPhoneType() + "\n";
    str += "SimCountryIso = " + tm.getSimCountryIso() + "\n";
    str += "SimOperator = " + tm.getSimOperator() + "\n";
    str += "SimOperatorName = " + tm.getSimOperatorName() + "\n";
    str += "SimSerialNumber = " + tm.getSimSerialNumber() + "\n";
    str += "SimState = " + tm.getSimState() + "\n";
    str += "SubscriberId(IMSI) = " + tm.getSubscriberId() + "\n";
    str += "VoiceMailNumber = " + tm.getVoiceMailNumber() + "\n";
    return str;
}
 
Example 8
Source Project: Ency   File: AppNetWorkUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 获取运行商名称
 *
 * @param context
 * @return 运营商名称
 */
private static String getOperatorName(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String operator = telephonyManager.getSimOperator();
    String operatorName = "";
    if (operator != null) {
        if (operator.equals("46000") || operator.equals("46002")) {
            operatorName = "移动";
        } else if (operator.equals("46001")) {
            operatorName = "联通";
        } else if (operator.equals("46003")) {
            operatorName = "电信";
        }
    }
    return operatorName;
}
 
Example 9
Source Project: AndroidUtilCode   File: PhoneUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Return the sim operator using mnc.
 *
 * @return the sim operator
 */
public static String getSimOperatorByMnc() {
    TelephonyManager tm = getTelephonyManager();
    String operator = tm.getSimOperator();
    if (operator == null) return "";
    switch (operator) {
        case "46000":
        case "46002":
        case "46007":
        case "46020":
            return "中国移动";
        case "46001":
        case "46006":
        case "46009":
            return "中国联通";
        case "46003":
        case "46005":
        case "46011":
            return "中国电信";
        default:
            return operator;
    }
}
 
Example 10
Source Project: KeyboardView   File: SystemUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 获取Sim卡运营商名称
 * <p>中国移动、如中国联通、中国电信</p>
 *
 * @param context 上下文
 * @return 移动网络运营商名称
 */
public static String getSimOperatorByMnc(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String operator = tm != null ? tm.getSimOperator() : null;
    if (operator == null) return null;
    switch (operator) {
        case "46000":
        case "46002":
        case "46007":
            return "中国移动";
        case "46001":
            return "中国联通";
        case "46003":
            return "中国电信";
        default:
            return operator;
    }
}
 
Example 11
private void subscriptionOrSimChanged(Context context) {
    if (DEBUG) Log.d(TAG, "received SIM related action: ");
    TelephonyManager phone = (TelephonyManager)
            mContext.getSystemService(Context.TELEPHONY_SERVICE);
    CarrierConfigManager configManager = (CarrierConfigManager)
            mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);
    String mccMnc = phone.getSimOperator();
    boolean isKeepLppProfile = false;
    if (!TextUtils.isEmpty(mccMnc)) {
        if (DEBUG) Log.d(TAG, "SIM MCC/MNC is available: " + mccMnc);
        synchronized (mLock) {
            if (configManager != null) {
                PersistableBundle b = configManager.getConfig();
                if (b != null) {
                    isKeepLppProfile =
                            b.getBoolean(CarrierConfigManager.KEY_PERSIST_LPP_MODE_BOOL);
                }
            }
            if (isKeepLppProfile) {
                // load current properties for the carrier
                loadPropertiesFromResource(context, mProperties);
                String lpp_profile = mProperties.getProperty("LPP_PROFILE");
                // set the persist property LPP_PROFILE for the value
                if (lpp_profile != null) {
                    SystemProperties.set(LPP_PROFILE, lpp_profile);
                }
            } else {
                // reset the persist property
                SystemProperties.set(LPP_PROFILE, "");
            }
            reloadGpsProperties(context, mProperties);
            mNIHandler.setSuplEsEnabled(mSuplEsEnabled);
        }
    } else {
        if (DEBUG) Log.d(TAG, "SIM MCC/MNC is still not available");
    }
}
 
Example 12
/**
 * Returns the MCC+MNC (mobile country code + mobile network code) as
 * the numeric name of the current SIM operator.
 */
@CalledByNative
private static String getSimOperator() {
    TelephonyManager telephonyManager =
            (TelephonyManager) ContextUtils.getApplicationContext().getSystemService(
                    Context.TELEPHONY_SERVICE);
    if (telephonyManager == null) return "";
    return telephonyManager.getSimOperator();
}
 
Example 13
/**
 * 检查手机是否有sim卡
 */
public static boolean hasSim(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String operator = tm.getSimOperator();
    if (TextUtils.isEmpty(operator)) {
        return false;
    }
    return true;
}
 
Example 14
/**
 * Returns the MCC+MNC (mobile country code + mobile network code) as
 * the numeric name of the current SIM operator.
 */
@CalledByNative
private static String getSimOperator() {
    TelephonyManager telephonyManager =
            (TelephonyManager) ContextUtils.getApplicationContext().getSystemService(
                    Context.TELEPHONY_SERVICE);
    if (telephonyManager == null) return "";
    return telephonyManager.getSimOperator();
}
 
Example 15
protected String getBestGuessMobileNetworkCode(Configuration configuration) {
    TelephonyManager telephonyManager = (TelephonyManager) getActivity().getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager != null) {
        if (telephonyManager.getSimState() == TelephonyManager.SIM_STATE_READY) {
            String simOperator = telephonyManager.getSimOperator();
            if (simOperator != null && simOperator.length() > 3) {
                return simOperator.substring(3);
            }
        }
    }
    Log.w(TAG, "Falling back to configuration's MNC which is missing info about any 0 prefixing. MNC is [" + configuration.mnc + "]");
    return Integer.toString(configuration.mnc); // TODO: Should we warn the user that if the is number 10-99 it might have 0 prefixed and if the number is 0-9 it might have 0 or 00 prefixed?
}
 
Example 16
Source Project: NIM_Android_UIKit   File: NetworkUtil.java    License: MIT License 5 votes vote down vote up
public static String getSimOperator(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm != null) {
        return tm.getSimOperator();
    }
    return null;
}
 
Example 17
public void setContext(Context context) {
    this.context = context;
    gsfVersionProvider = new NativeGsfVersionProvider(context);
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (null != tm) {
        networkOperator = null != tm.getNetworkOperator() ? tm.getNetworkOperator() : "";
        simOperator = null != tm.getSimOperator() ? tm.getSimOperator() : "";
    }
}
 
Example 18
/** get the carrier number */
public String getCarrier() {
	TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
	if (tm == null) {
		return "-1";
	}

	String operator = tm.getSimOperator();
	if (TextUtils.isEmpty(operator)) {
		operator = "-1";
	}
	Ln.w("getCarrier =================>> ", operator);
	return operator;
}
 
Example 19
/**
 * 获取系统的其他信息,组成json
 */
public static String getOther(Context context) {
    StringBuilder sb = new StringBuilder();
    sb.append("{");
    try {
        sb.append("\"kvn\":\"").append(BuildConfig.VERSION_NAME).append("\"").append(",");
        sb.append("\"kvc\":\"").append(BuildConfig.VERSION_CODE).append("\"").append(",");
        sb.append("\"sid\":\"").append(object2String(Build.ID)).append("\"").append(",");
        sb.append("\"sdv\":\"").append(object2String(Build.DEVICE)).append("\"").append(",");
        sb.append("\"sbr\":\"").append(object2String(Build.BRAND)).append("\"").append(",");
        sb.append("\"smo\":\"").append(object2String(Build.MODEL)).append("\"").append(",");
        sb.append("\"spd\":\"").append(object2String(Build.PRODUCT)).append("\"").append(",");
        sb.append("\"smf\":\"").append(object2String(Build.MANUFACTURER)).append("\"").append(",");
        sb.append("\"shw\":\"").append(object2String(Build.HARDWARE)).append("\"").append(",");
        sb.append("\"sfp\":\"").append(object2String(Build.FINGERPRINT)).append("\"").append(",");
        sb.append("\"stp\":\"").append(object2String(Build.TYPE)).append("\"").append(",");
        sb.append("\"shs\":\"").append(object2String(Build.HOST)).append("\"").append(",");
        sb.append("\"sbd\":\"").append(object2String(Build.BOARD)).append("\"").append(",");
        sb.append("\"stm\":\"").append(object2String(Build.TIME)).append("\"").append(",");
        sb.append("\"sca\":\"").append(object2String(Build.CPU_ABI)).append("\"").append(",");
        sb.append("\"sbl\":\"").append(object2String(Build.BOOTLOADER)).append("\"").append(",");
        sb.append("\"sdp\":\"").append(object2String(Build.DISPLAY)).append("\"").append(",");
        sb.append("\"stg\":\"").append(object2String(Build.TAGS)).append("\"").append(",");
        sb.append("\"svr\":\"").append(object2String(Build.VERSION.RELEASE)).append("\"").append(",");
        sb.append("\"svs\":\"").append(object2String(Build.VERSION.SDK_INT)).append("\"").append(",");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            sb.append("\"svb\":\"").append(object2String(Build.VERSION.BASE_OS)).append("\"").append(",");
        }
        sb.append("\"svc\":\"").append(object2String(Build.VERSION.CODENAME)).append("\"").append(",");
        sb.append("\"svi\":\"").append(object2String(Build.VERSION.INCREMENTAL)).append("\"").append(",");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            sb.append("\"svs\":\"").append(object2String(Build.VERSION.SECURITY_PATCH)).append("\"").append(",");
        }

        if (context != null) {
            TelephonyManager phone = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

            sb.append("\"avc\":\"").append(context.getPackageName()).append("\"").append(",");
            sb.append("\"avn\":\"").append(getVersionName(context)).append("\"").append(",");
            sb.append("\"aan\":\"").append(getAppName(context)).append("\"").append(",");
            if (phone != null) {
                if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
                    @SuppressLint("HardwareIds") String telephone = phone.getSimSerialNumber();
                    if (!TextUtils.isEmpty(telephone)) {
                        sb.append("\"psn\":\"").append(object2String(telephone)).append("\"").append(",");
                    }
                    @SuppressLint("HardwareIds") String subscriberId = phone.getSubscriberId();
                    if (!TextUtils.isEmpty(subscriberId)) {
                        sb.append("\"psi\":\"").append(object2String(subscriberId)).append("\"").append(",");
                    }
                }
                int phoneType = phone.getPhoneType();
                sb.append("\"ppt\":\"").append(object2String(phoneType)).append("\"").append(",");
                String simCountryIso = phone.getSimCountryIso();
                if (!TextUtils.isEmpty(simCountryIso)) {
                    sb.append("\"psc\":\"").append(object2String(simCountryIso)).append("\"").append(",");
                }
                String simOperator = phone.getSimOperator();
                if (!TextUtils.isEmpty(simOperator)) {
                    sb.append("\"pso\":\"").append(object2String(simOperator)).append("\"").append(",");
                }
                String simOperatorName = phone.getSimOperatorName();
                if (!TextUtils.isEmpty(simOperatorName)) {
                    sb.append("\"psn\":\"").append(object2String(simOperatorName)).append("\"").append(",");
                }
            }

            if (context.getResources() != null) {
                DisplayMetrics metrics = context.getResources().getDisplayMetrics();
                if (metrics != null) {
                    sb.append("\"dmd\":\"").append(object2String(metrics.density)).append("\"").append(",");
                    sb.append("\"ddp\":\"").append(object2String(metrics.densityDpi)).append("\"").append(",");
                    sb.append("\"dmx\":\"").append(object2String(metrics.xdpi)).append("\"").append(",");
                    sb.append("\"dmy\":\"").append(object2String(metrics.ydpi)).append("\"").append(",");
                    sb.append("\"dsd\":\"").append(object2String(metrics.scaledDensity)).append("\"").append(",");
                }
            }
        }

        sb = sb.deleteCharAt(sb.length() - 1);
    } catch (Exception ignored) {
    }
    sb.append("}");
    return sb.toString();
}
 
Example 20
Source Project: Ticket-Analysis   File: PhoneUtils.java    License: MIT License 4 votes vote down vote up
/**
 * 获取手机状态信息
 * <p>需添加权限<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
 * <p>返回如下
 * <pre>
 * DeviceId(IMEI) = 99000311726612
 * DeviceSoftwareVersion = 00
 * Line1Number =
 * NetworkCountryIso = cn
 * NetworkOperator = 46003
 * NetworkOperatorName = 中国电信
 * NetworkType = 6
 * honeType = 2
 * SimCountryIso = cn
 * SimOperator = 46003
 * SimOperatorName = 中国电信
 * SimSerialNumber = 89860315045710604022
 * SimState = 5
 * SubscriberId(IMSI) = 460030419724900
 * VoiceMailNumber = *86
 * <pre/>
 */
public static String getPhoneStatus(Context context) {
    TelephonyManager tm = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    String str = "";
    str += "DeviceId(IMEI) = " + tm.getDeviceId() + "\n";
    str += "DeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion() + "\n";
    str += "Line1Number = " + tm.getLine1Number() + "\n";
    str += "NetworkCountryIso = " + tm.getNetworkCountryIso() + "\n";
    str += "NetworkOperator = " + tm.getNetworkOperator() + "\n";
    str += "NetworkOperatorName = " + tm.getNetworkOperatorName() + "\n";
    str += "NetworkType = " + tm.getNetworkType() + "\n";
    str += "honeType = " + tm.getPhoneType() + "\n";
    str += "SimCountryIso = " + tm.getSimCountryIso() + "\n";
    str += "SimOperator = " + tm.getSimOperator() + "\n";
    str += "SimOperatorName = " + tm.getSimOperatorName() + "\n";
    str += "SimSerialNumber = " + tm.getSimSerialNumber() + "\n";
    str += "SimState = " + tm.getSimState() + "\n";
    str += "SubscriberId(IMSI) = " + tm.getSubscriberId() + "\n";
    str += "VoiceMailNumber = " + tm.getVoiceMailNumber() + "\n";
    return str;
}