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

The following examples show how to use android.telephony.TelephonyManager#getNetworkOperator() . 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
Source File: JNIUtilities.java    From Telegram-FOSS with GNU General Public License v2.0 7 votes vote down vote up
public static String[] getCarrierInfo(){
	TelephonyManager tm=(TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
	if(Build.VERSION.SDK_INT>=24){
		tm=tm.createForSubscriptionId(SubscriptionManager.getDefaultDataSubscriptionId());
	}
	if(!TextUtils.isEmpty(tm.getNetworkOperatorName())){
		String mnc="", mcc="";
		String carrierID=tm.getNetworkOperator();
		if(carrierID!=null && carrierID.length()>3){
			mcc=carrierID.substring(0, 3);
			mnc=carrierID.substring(3);
		}
		return new String[]{tm.getNetworkOperatorName(), tm.getNetworkCountryIso().toUpperCase(), mcc, mnc};
	}
	return null;
}
 
Example 2
Source File: Phone.java    From batteryhub with Apache License 2.0 6 votes vote down vote up
/**
 * Returns numeric mobile network code.
 *
 * @param context Application context
 * @return 2-3 digit network code
 */
public static String getMnc(final Context context) {
    TelephonyManager telephonyManager =
            (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String networkOperator = telephonyManager.getNetworkOperator();
    if (networkOperator != null && networkOperator.length() >= 5) {
        return networkOperator.substring(3);
    }
    String operatorProperty = "gsm.operator.numeric";
    if (telephonyManager.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) {
        operatorProperty = "ro.cdma.home.operator.numeric"; // CDMA
    }
    networkOperator = Specifications.getStringFromSystemProperty(context, operatorProperty);
    if (networkOperator != null && networkOperator.length() >= 5) {
        return networkOperator.substring(3);
    }
    return "Unknown";
}
 
Example 3
Source File: VenvyDeviceUtil.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 获取设备拨号运营商  运营商信息 0:其他,1:移动,2:联通,3:电信
 *
 * @return ["中国电信CTCC":3]["中国联通CUCC:2]["中国移动CMCC":1]["other":0]["无sim卡":-1]
 */
public static int getSubscriptionOperatorType(Context context) {
    int opeType = 0;
    // No sim
    if (!hasSim(context)) {
        return opeType;
    }

    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String operator = tm.getNetworkOperator();
    // 中国联通
    if ("46001".equals(operator) || "46006".equals(operator) || "46009".equals(operator)) {
        opeType = 2;
        // 中国移动
    } else if ("46000".equals(operator) || "46002".equals(operator) || "46004".equals(operator) || "46007".equals(operator)) {
        opeType = 1;
        // 中国电信
    } else if ("46003".equals(operator) || "46005".equals(operator) || "46011".equals(operator)) {
        opeType = 3;
    } else {
        opeType = 0;
    }
    return opeType;
}
 
Example 4
Source File: DeviceUtils.java    From SprintNBA with Apache License 2.0 6 votes vote down vote up
/**
 * 获取手机网络运营商类型
 *
 * @param context
 * @return
 */
public static String getPhoneISP(Context context) {
    if (context == null) {
        return "";
    }
    TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String teleCompany = "";
    String np = manager.getNetworkOperator();

    if (np != null) {
        if (np.equals(CMCC_ISP) || np.equals(CMCC2_ISP)) {
            teleCompany = "中国移动";
        } else if (np.startsWith(CU_ISP)) {
            teleCompany = "中国联通";
        } else if (np.startsWith(CT_ISP)) {
            teleCompany = "中国电信";
        }
    }
    return teleCompany;
}
 
Example 5
Source File: RxDeviceTool.java    From RxTools-master with 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 6
Source File: DeviceUtils.java    From BookReader with Apache License 2.0 6 votes vote down vote up
/**
 * 获取手机网络运营商类型
 *
 * @param context
 * @return
 */
public static String getPhoneISP(Context context) {
    if (context == null) {
        return "";
    }
    TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String teleCompany = "";
    String np = manager.getNetworkOperator();

    if (np != null) {
        if (np.equals(CMCC_ISP) || np.equals(CMCC2_ISP)) {
            teleCompany = "中国移动";
        } else if (np.startsWith(CU_ISP)) {
            teleCompany = "中国联通";
        } else if (np.startsWith(CT_ISP)) {
            teleCompany = "中国电信";
        }
    }
    return teleCompany;
}
 
Example 7
Source File: NetworkUtil.java    From NIM_Android_UIKit with MIT License 5 votes vote down vote up
public static String getNetworkOperator(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm != null) {
        return tm.getNetworkOperator();
    }
    return null;
}
 
Example 8
Source File: CorrectPasswordFirst.java    From MyHearts with Apache License 2.0 5 votes vote down vote up
private String getMCC() {
    TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    // 返回当前手机注册的网络运营商所在国家的MCC+MNC. 如果没注册到网络就为空.
    String networkOperator = tm.getNetworkOperator();
    if (!TextUtils.isEmpty(networkOperator)) {
        return networkOperator;
    }

    // 返回SIM卡运营商所在国家的MCC+MNC. 5位或6位. 如果没有SIM卡返回空
    return tm.getSimOperator();
}
 
Example 9
Source File: NativeDeviceInfoProvider.java    From YalpStore with GNU General Public License v2.0 5 votes vote down vote up
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 10
Source File: hi.java    From letv with Apache License 2.0 5 votes vote down vote up
public String d() {
    TelephonyManager telephonyManager = (TelephonyManager) hn.a().c().getSystemService("phone");
    if (telephonyManager == null) {
        return null;
    }
    return telephonyManager.getNetworkOperator();
}
 
Example 11
Source File: NetworkUtil.java    From RxZhihuDaily with MIT License 5 votes vote down vote up
public static String getNetworkOperator(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm != null) {
        return tm.getNetworkOperator();
    }
    return null;
}
 
Example 12
Source File: TelephonyActivity.java    From nearbydemo with Eclipse Public License 1.0 5 votes vote down vote up
private String getJsonCellPos() throws JSONException {
	TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
	GsmCellLocation location = (GsmCellLocation) tm.getCellLocation();
	if (location == null) {
		return null;
	}
	int cid = location.getCid();
	int lac = location.getLac();
	String netOperator = tm.getNetworkOperator();
	int mcc = Integer.valueOf(netOperator.substring(0, 3));
	int mnc = Integer.valueOf(netOperator.substring(3, 5));
	System.out.println("cid" + cid + ",lac" + lac + ",mcc" + mcc + "" + ",mnc" + mnc);
	JSONObject jsonCellPos = new JSONObject();
	jsonCellPos.put("version", "1.1.0");
	jsonCellPos.put("host", "maps.google.com");

	JSONArray array = new JSONArray();
	JSONObject json1 = new JSONObject();
	json1.put("location_area_code", "" + lac + "");
	json1.put("mobile_country_code", "" + mcc + "");
	json1.put("mobile_network_code", "" + mnc + "");
	json1.put("age", 0);
	json1.put("cell_id", "" + cid + "");
	array.put(json1);
	jsonCellPos.put("cell_towers", array);
	return jsonCellPos.toString();
}
 
Example 13
Source File: SmsUtilities.java    From geopaparazzi with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Send an SMS.
 *
 * @param context     the {@link Context} to use.
 * @param number      the number to which to send the SMS.
 * @param msg         the SMS body text.
 * @param sendMessage if <code>true</code>, a {@link Toast} tells the user that the message was sent.
 */
public static void sendSMS(Context context, String number, String msg, boolean sendMessage) {
    Object systemService = context.getSystemService(Context.TELEPHONY_SERVICE);
    if (systemService instanceof TelephonyManager) {
        TelephonyManager telManager = (TelephonyManager) systemService;
        String networkOperator = telManager.getNetworkOperator();
        if (networkOperator.trim().length() == 0) {
            GPDialogs.warningDialog(context, "This functionality works only when connected to a GSM network.", null);
            return;
        }
    }

    SmsManager mng = SmsManager.getDefault();
    PendingIntent dummyEvent = PendingIntent.getBroadcast(context, 0, new Intent("com.devx.SMSExample.IGNORE_ME"), 0);
    try {
        if (msg.length() > 160) {
            msg = msg.substring(0, 160);
            if (GPLog.LOG)
                GPLog.addLogEntry("SMSUTILITIES", "Trimming msg to: " + msg);
        }
        mng.sendTextMessage(number, null, msg, dummyEvent, dummyEvent);
        if (sendMessage)
            GPDialogs.toast(context, R.string.message_sent, Toast.LENGTH_LONG);
    } catch (Exception e) {
        GPLog.error(context, e.getLocalizedMessage(), e);
        GPDialogs.warningDialog(context, "An error occurred while sending the SMS.", null);
    }
}
 
Example 14
Source File: TelephonyActivity.java    From nearbydemo with Eclipse Public License 1.0 5 votes vote down vote up
public String getJsonCellPos1() {
	TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
	GsmCellLocation location = (GsmCellLocation) tm.getCellLocation();
	if (location == null) {
		return null;
	}
	int cid = location.getCid();
	int lac = location.getLac();
	String netOperator = tm.getNetworkOperator();
	int mcc = Integer.valueOf(netOperator.substring(0, 3));
	int mnc = Integer.valueOf(netOperator.substring(3, 5));
	System.out.println("cid" + cid + ",lac" + lac + ",mcc" + mcc + "" + ",mnc" + mnc);
	holder = new JSONObject();
	JSONArray array = new JSONArray();
	JSONObject data = new JSONObject();
	try {
		holder.put("version", "1.1.0");
		holder.put("host", "maps.google.com");
		holder.put("address_language", "zh_CN");
		holder.put("request_address", true);
		holder.put("radio_type", "gsm");
		holder.put("carrier", "HTC");
		data.put("cell_id", cid);
		data.put("location_area_code", lac);
		data.put("mobile_countyr_code", mcc);
		data.put("mobile_network_code", mnc);
		array.put(data);
		holder.put("cell_towers", array);
		Log.i(TAG, "JSON��Ϣ��" + holder.toString());
		return holder.toString();
	} catch (JSONException e) {
		e.printStackTrace();
	}
	return null;

}
 
Example 15
Source File: CollectorService.java    From TowerCollector with Mozilla Public License 2.0 5 votes vote down vote up
private void processCellLocation(TelephonyManager telephonyManager, CellLocation cellLocation, List<NeighboringCellInfo> neighboringCells) {
    // get network type
    int networkTypeInt = telephonyManager.getNetworkType();
    NetworkGroup networkType = NetworkTypeUtils.getNetworkGroup(networkTypeInt);
    // get network operator (may be unreliable for CDMA)
    String networkOperatorCode = telephonyManager.getNetworkOperator();
    String networkOperatorName = telephonyManager.getNetworkOperatorName();
    Timber.d("processCellLocation(): Operator code = '%s', name = '%s'", networkOperatorCode, networkOperatorName);
    Timber.d("processCellLocation(): Reported %s neighboring cells", (neighboringCells != null ? neighboringCells.size() : null));
    measurementUpdater.setLastCellLocation(cellLocation, networkType, networkOperatorCode, networkOperatorName, neighboringCells);
}
 
Example 16
Source File: AndroidNetworkLibrary.java    From cronet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns the MCC+MNC (mobile country code + mobile network code) as
 * the numeric name of the current registered operator.
 */
@CalledByNative
private static String getNetworkOperator() {
    TelephonyManager telephonyManager =
            (TelephonyManager) ContextUtils.getApplicationContext().getSystemService(
                    Context.TELEPHONY_SERVICE);
    if (telephonyManager == null) return "";
    return telephonyManager.getNetworkOperator();
}
 
Example 17
Source File: DeviceInfo.java    From Cangol-appcore with Apache License 2.0 5 votes vote down vote up
public static String getNetworkOperator(Context context) {
    String provider = "";
    try {
        final TelephonyManager manager = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        provider = manager.getNetworkOperator();
    } catch (Exception e) {
        Log.e("getNetworkOperatorName", "" + e.getMessage(), e);
    }
    return provider;
}
 
Example 18
Source File: Gsm.java    From batteryhub with Apache License 2.0 5 votes vote down vote up
public static CellInfo getCellInfo(Context context) {
    CellInfo cellInfo = new CellInfo();

    TelephonyManager manager = (TelephonyManager)
            context.getSystemService(Context.TELEPHONY_SERVICE);

    String netOperator = manager.getNetworkOperator();

    // Fix crash when not connected to network (airplane mode, underground,
    // etc)
    if (netOperator == null || netOperator.length() < 3) {
        return cellInfo;
    }

    /*
     * FIXME: Actually check for mobile network status == connected before
     * doing this stuff.
     */

    if (Phone.getType(context).equals(PHONE_TYPE_CDMA)) {
        CdmaCellLocation cdmaLocation = (CdmaCellLocation) manager.getCellLocation();

        cellInfo.cid = cdmaLocation.getBaseStationId();
        cellInfo.lac = cdmaLocation.getNetworkId();
        cellInfo.mnc = cdmaLocation.getSystemId();
        cellInfo.mcc = Integer.parseInt(netOperator.substring(0, 3));
        cellInfo.radioType = Network.getMobileNetworkType(context);
    } else if (Phone.getType(context).equals(PHONE_TYPE_GSM)) {
        GsmCellLocation gsmLocation = (GsmCellLocation) manager.getCellLocation();

        cellInfo.mcc = Integer.parseInt(netOperator.substring(0, 3));
        cellInfo.mnc = Integer.parseInt(netOperator.substring(3));
        cellInfo.lac = gsmLocation.getLac();
        cellInfo.cid = gsmLocation.getCid();
        cellInfo.radioType = Network.getMobileNetworkType(context);
    }

    return cellInfo;
}
 
Example 19
Source File: NetUtil.java    From ESeal with Apache License 2.0 4 votes vote down vote up
/**
 * 获取手机基站运行商
 */
public static String getTelephonyNetWorkOperator(Activity activity) {
    TelephonyManager telephonyManager = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
    return telephonyManager.getNetworkOperator();
}
 
Example 20
Source File: NetUtil.java    From ESeal with Apache License 2.0 4 votes vote down vote up
/**
 * 获取手机基站运行商
 */
public static String getTelephonyNetWorkOperator(Activity activity) {
    TelephonyManager telephonyManager = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
    return telephonyManager.getNetworkOperator();
}