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

The following examples show how to use android.telephony.TelephonyManager#getSubscriberId() . 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: NetworkUtils.java    From letv with Apache License 2.0 6 votes vote down vote up
public static int getOperator() {
    Context context = BaseApplication.getInstance().getApplicationContext();
    NetworkInfo networkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
    String imsi = "";
    if (networkInfo != null && networkInfo.isAvailable()) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService("phone");
        imsi = tm.getSimOperator();
        if (TextUtils.isEmpty(imsi)) {
            imsi = tm.getSubscriberId();
        }
    }
    if (TextUtils.isEmpty(imsi)) {
        return 0;
    }
    return getOperatorByNetworkNumber(imsi);
}
 
Example 2
Source File: DeviceUtils.java    From Android-utils with 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 File: Tools.java    From BigApp_Discuz_Android with Apache License 2.0 6 votes vote down vote up
/**
 * 获取手机服务商信息 需要加入权限<uses-permission
 * android:name="android.permission.READ_PHONE_STATE"/>
 */
public static String getNetOperator(Context context) {

	String netOperator = "other";
	TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
	if (telephonyManager != null) {
		// 返回唯一的用户ID;就是这张卡的编号神马的
		String imsi = telephonyManager.getSubscriberId();
		if (TextUtils.isEmpty(imsi)) {
			return netOperator;
		}
		// IMSI号前面3位460是国家,紧接着后面2位00 02是中国移动,01是中国联通,03是中国电信。
		if (imsi.startsWith("46000") || imsi.startsWith("46002") || imsi.startsWith("46007")) {
			netOperator = "chinaMobile";// 中国移动
		} else if (imsi.startsWith("46001") || imsi.startsWith("46006")) {
			netOperator = "chinaUnicom";// 中国联通
		} else if (imsi.startsWith("46003") || imsi.startsWith("46005")) {
			netOperator = "chinaTelecom";// "chinaNet";//中国电信
		} else if (imsi.startsWith("46020")) {
			netOperator = "chinaTietong";// 中国铁通
		}
	}
	return netOperator;

}
 
Example 4
Source File: NetworkUtil.java    From SimpleProject with MIT License 6 votes vote down vote up
/**
 * 获取运行商信息
 * @param context
 * @return
 */
@SuppressLint("MissingPermission")
public static String getCarrier(Context context) {
	TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
	if (tm == null) {
		return CARRIER_TYPE_UNKNOWN;
	}
	 String subscriberId = tm.getSubscriberId();
	if (TextUtils.isEmpty(subscriberId)) {
		return CARRIER_TYPE_UNKNOWN;
	}

	if (subscriberId.startsWith(CARRIER_TYPE_CMCC_CODE_46000)
			|| subscriberId.startsWith(CARRIER_TYPE_CMCC_CODE_46002)
			|| subscriberId.startsWith(CARRIER_TYPE_CMCC_CODE_46007)) {
		return CARRIER_TYPE_CMCC;
	} else if (subscriberId.startsWith(CARRIER_TYPE_CUCC_CODE_46001)) {
		return CARRIER_TYPE_CUCC;
	} else if (subscriberId.startsWith(CARRIER_TYPE_CTCC_CODE_46003)) {
		return CARRIER_TYPE_CTCC;
	}

	return CARRIER_TYPE_UNKNOWN;
}
 
Example 5
Source File: XLUtil.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
public static NetWorkCarrier getNetWorkCarrier(Context context) {
    if (context != null) {
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
        if (telephonyManager != null) {
            try {
                String subscriberId = telephonyManager.getSubscriberId();
                if(subscriberId != null) {
                    if (subscriberId.startsWith("46000") || subscriberId.startsWith("46002")) {
                        return NetWorkCarrier.CMCC;
                    }
                    if (subscriberId.startsWith("46001")) {
                        return NetWorkCarrier.CU;
                    }
                    if (subscriberId.startsWith("46003")) {
                        return NetWorkCarrier.CT;
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    return NetWorkCarrier.UNKNOWN;
}
 
Example 6
Source File: TelephoneUtil.java    From zone-sdk with MIT License 5 votes vote down vote up
/**
 * Print telephone info.
 */
public static String printTelephoneInfo(Context context) {
    Date date = new Date(System.currentTimeMillis());
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String time = dateFormat.format(date);
    StringBuilder sb = new StringBuilder();
    sb.append("_______ 手机信息  ").append(time).append(" ______________");
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String IMSI = tm.getSubscriberId();
    //IMSI前面三位460是国家号码,其次的两位是运营商代号,00、02是中国移动,01是联通,03是电信。
    String providerName = null;
    if (IMSI != null) {
        if (IMSI.startsWith("46000") || IMSI.startsWith("46002")) {
            providerName = "中国移动";
        } else if (IMSI.startsWith("46001")) {
            providerName = "中国联通";
        } else if (IMSI.startsWith("46003")) {
            providerName = "中国电信";
        }
    }
    sb.append(providerName).append("  手机号:").append(tm.getLine1Number()).append(" IMSI是:").append(IMSI);
    sb.append("\nDeviceID(IMEI)       :").append(tm.getDeviceId());
    sb.append("\nDeviceSoftwareVersion:").append(tm.getDeviceSoftwareVersion());
    sb.append("\ngetLine1Number       :").append(tm.getLine1Number());
    sb.append("\nNetworkCountryIso    :").append(tm.getNetworkCountryIso());
    sb.append("\nNetworkOperator      :").append(tm.getNetworkOperator());
    sb.append("\nNetworkOperatorName  :").append(tm.getNetworkOperatorName());
    sb.append("\nNetworkType          :").append(tm.getNetworkType());
    sb.append("\nPhoneType            :").append(tm.getPhoneType());
    sb.append("\nSimCountryIso        :").append(tm.getSimCountryIso());
    sb.append("\nSimOperator          :").append(tm.getSimOperator());
    sb.append("\nSimOperatorName      :").append(tm.getSimOperatorName());
    sb.append("\nSimSerialNumber      :").append(tm.getSimSerialNumber());
    sb.append("\ngetSimState          :").append(tm.getSimState());
    sb.append("\nSubscriberId         :").append(tm.getSubscriberId());
    sb.append("\nVoiceMailNumber      :").append(tm.getVoiceMailNumber());

    LogZSDK.INSTANCE.i( sb.toString());
    return sb.toString();
}
 
Example 7
Source File: LauncherUtil.java    From apollo-DuerOS with Apache License 2.0 5 votes vote down vote up
/**
 * Get IMSI, international mobile user identification code(IMSI:International Mobile Subscriber Identification Number)
 */
public static String getIMSI() {
    if (TextUtils.isEmpty(mImsi)) {
        TelephonyManager teleMgr = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
        mImsi = teleMgr.getSubscriberId();
    }

    if (mImsi == null) {
        mImsi = "";
    }

    return mImsi;
}
 
Example 8
Source File: EmulatorDetector.java    From android-emulator-detector with Apache License 2.0 5 votes vote down vote up
private boolean checkImsi() {
    TelephonyManager telephonyManager =
        (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
    @SuppressLint("HardwareIds") String imsi = telephonyManager.getSubscriberId();

    for (String known_imsi : IMSI_IDS) {
        if (known_imsi.equalsIgnoreCase(imsi)) {
            log("Check imsi is detected");
            return true;
        }
    }
    return false;
}
 
Example 9
Source File: TelephoneUtil.java    From AndroidBase with Apache License 2.0 5 votes vote down vote up
/**
 * Print telephone info.
 */
public static String printTelephoneInfo(Context context) {
    Date date = new Date(System.currentTimeMillis());
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String time = dateFormat.format(date);
    StringBuilder sb = new StringBuilder();
    sb.append("_______ 手机信息  ").append(time).append(" ______________");
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String IMSI = tm.getSubscriberId();
    //IMSI前面三位460是国家号码,其次的两位是运营商代号,00、02是中国移动,01是联通,03是电信。
    String providerName = null;
    if (IMSI != null) {
        if (IMSI.startsWith("46000") || IMSI.startsWith("46002")) {
            providerName = "中国移动";
        } else if (IMSI.startsWith("46001")) {
            providerName = "中国联通";
        } else if (IMSI.startsWith("46003")) {
            providerName = "中国电信";
        }
    }
    sb.append(providerName).append("  手机号:").append(tm.getLine1Number()).append(" IMSI是:").append(IMSI);
    sb.append("\nDeviceID(IMEI)       :").append(tm.getDeviceId());
    sb.append("\nDeviceSoftwareVersion:").append(tm.getDeviceSoftwareVersion());
    sb.append("\ngetLine1Number       :").append(tm.getLine1Number());
    sb.append("\nNetworkCountryIso    :").append(tm.getNetworkCountryIso());
    sb.append("\nNetworkOperator      :").append(tm.getNetworkOperator());
    sb.append("\nNetworkOperatorName  :").append(tm.getNetworkOperatorName());
    sb.append("\nNetworkType          :").append(tm.getNetworkType());
    sb.append("\nPhoneType            :").append(tm.getPhoneType());
    sb.append("\nSimCountryIso        :").append(tm.getSimCountryIso());
    sb.append("\nSimOperator          :").append(tm.getSimOperator());
    sb.append("\nSimOperatorName      :").append(tm.getSimOperatorName());
    sb.append("\nSimSerialNumber      :").append(tm.getSimSerialNumber());
    sb.append("\ngetSimState          :").append(tm.getSimState());
    sb.append("\nSubscriberId         :").append(tm.getSubscriberId());
    sb.append("\nVoiceMailNumber      :").append(tm.getVoiceMailNumber());

    LogUtils.i(sb.toString());
    return sb.toString();
}
 
Example 10
Source File: VDMobileUtil.java    From NewsMe with Apache License 2.0 5 votes vote down vote up
public static int getProvider(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String IMSI = telephonyManager.getSubscriberId();
    if (IMSI.startsWith("46000") || IMSI.startsWith("46002")) {
        return CHINA_MOBILE;
    } else if (IMSI.startsWith("46001")) {
        return CHINA_UNICOM;
    } else if (IMSI.startsWith("46003")) {
        return CHINA_TELECOM;
    }
    return PROVIDER_UNKNOWN;
}
 
Example 11
Source File: PhoneStateUtil.java    From VSigner with GNU General Public License v2.0 5 votes vote down vote up
/**
	 * 获取本机手机号码
	 * @param context
	 * @return
	 */
	public static String getPhoneIMSI(Context context){   
		TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
//		String deviceid = tm.getDeviceId(); 
//		String tel = tm.getLine1Number(); 
//		String imei =tm.getSimSerialNumber();
		String imsi =tm.getSubscriberId();
	    return imsi;
	}
 
Example 12
Source File: ImsiUtil.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 展讯芯片的判断
 * @return
 */
public IMSInfo initSpreadDoubleSim() {
    IMSInfo imsInfo = null;
    try {
        Class<?> c = Class
                .forName("com.android.internal.telephony.PhoneFactory");
        Method m = c.getMethod("getServiceName", String.class, int.class);
        String spreadTmService = (String) m.invoke(c,
                Context.TELEPHONY_SERVICE, 1);
        TelephonyManager tm = (TelephonyManager) mContext
                .getSystemService(Context.TELEPHONY_SERVICE);
        imsi_1 = tm.getSubscriberId();
        imei_1 = tm.getDeviceId();
        TelephonyManager tm1 = (TelephonyManager) mContext
                .getSystemService(spreadTmService);
        imsi_2 = tm1.getSubscriberId();
        imei_2 = tm1.getDeviceId();
        imsInfo = new IMSInfo();
        imsInfo.chipName = "展讯芯片";
        imsInfo.imei_1 = imei_1;
        imsInfo.imei_2 = imei_2;
        imsInfo.imsi_1 = imsi_1;
        imsInfo.imsi_2 = imsi_2;
    } catch (Exception e) {
        imsInfo = null;
        return imsInfo;
    }
    return imsInfo;
}
 
Example 13
Source File: DeviceInfoUtil.java    From FloatUtil with MIT License 5 votes vote down vote up
public static String getIMSI(Context context) {
    if(context == null){
        return null;
    }
    if(TextUtils.isEmpty(imsi)) {
        TelephonyManager mTelephonyMgr = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        try { //Android 6.0异常捕获
            imsi = mTelephonyMgr.getSubscriberId();
        }catch (SecurityException e){
            Log.e(TAG,e.getMessage());
        }
    }
    return imsi;
}
 
Example 14
Source File: DeviceUtil.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 检测imsi id是不是“310260000000000”
 */
private static Boolean checkByImsiIDS(Context context){
    TelephonyManager telephonyManager = (TelephonyManager)
            context.getSystemService(Context.TELEPHONY_SERVICE);
    String imsiid = telephonyManager.getSubscriberId();
    for (String knowimsi : kKNOWN_IMSI_IDS) {
        if (knowimsi.equalsIgnoreCase(imsiid)) {
            Logger.v("Find imsi ids: 310260000000000!");
            return true;
        }
    }
    Logger.v("Not Find imsi ids: 310260000000000!");
    return false;
}
 
Example 15
Source File: TelephoneUtil.java    From zone-sdk with MIT License 5 votes vote down vote up
/**
 * MTK Phone.
 *
 * 获取 MTK 神机的双卡 IMSI、IMSI 信息
 */
public static TeleInfo getMtkTeleInfo2(Context context) {
    TeleInfo teleInfo = new TeleInfo();
    try {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        Class<?> phone = Class.forName("com.android.internal.telephony.Phone");
        Field fields1 = phone.getField("GEMINI_SIM_1");
        fields1.setAccessible(true);
        int simId_1 = (Integer) fields1.get(null);
        Field fields2 = phone.getField("GEMINI_SIM_2");
        fields2.setAccessible(true);
        int simId_2 = (Integer) fields2.get(null);

        Method getDefault = TelephonyManager.class.getMethod("getDefault", int.class);
        TelephonyManager tm1 = (TelephonyManager) getDefault.invoke(tm, simId_1);
        TelephonyManager tm2 = (TelephonyManager) getDefault.invoke(tm, simId_2);

        String imsi_1 = tm1.getSubscriberId();
        String imsi_2 = tm2.getSubscriberId();
        teleInfo.imsi_1 = imsi_1;
        teleInfo.imsi_2 = imsi_2;

        String imei_1 = tm1.getDeviceId();
        String imei_2 = tm2.getDeviceId();
        teleInfo.imei_1 = imei_1;
        teleInfo.imei_2 = imei_2;

        int phoneType_1 = tm1.getPhoneType();
        int phoneType_2 = tm2.getPhoneType();
        teleInfo.phoneType_1 = phoneType_1;
        teleInfo.phoneType_2 = phoneType_2;
    } catch (Exception e) {
        e.printStackTrace();
    }
    LogZSDK.INSTANCE.i("MTK2: " + teleInfo);
    return teleInfo;
}
 
Example 16
Source File: DeviceUtils.java    From BookReader with Apache License 2.0 4 votes vote down vote up
public static String getIMSI(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String IMSI = telephonyManager.getSubscriberId();
    return IMSI;
}
 
Example 17
Source File: PhoneUtils.java    From Ticket-Analysis with 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;
}
 
Example 18
Source File: DeviceUtils.java    From SprintNBA with Apache License 2.0 4 votes vote down vote up
public static String getIMSI(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String IMSI = telephonyManager.getSubscriberId();
    return IMSI;
}
 
Example 19
Source File: TelephoneUtil.java    From android-common with Apache License 2.0 3 votes vote down vote up
/**
 * IMSI是国际移动用户识别码的简称(International Mobile Subscriber Identity)
 * IMSI共有15位,其结构如下:
 * MCC+MNC+MIN
 * MCC:Mobile Country Code,移动国家码,共3位,中国为460;
 * MNC:Mobile NetworkCode,移动网络码,共2位
 * 在中国,移动的代码为电00和02,联通的代码为01,电信的代码为03
 * 合起来就是(也是Android手机中APN配置文件中的代码):
 * 中国移动:46000 46002
 * 中国联通:46001
 * 中国电信:46003
 * 举例,一个典型的IMSI号码为460030912121001
 */
public static String getIMSI(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String IMSI = telephonyManager.getSubscriberId();
    Log.i(TAG, " IMSI:" + IMSI);
    return IMSI;
}
 
Example 20
Source File: UID.java    From cordova-plugin-uid with MIT License 2 votes vote down vote up
/**
 * Get the device's International mobile Subscriber Identity (IMSI).
 *
 * @param context The context of the main Activity.
 * @return
 */
public String getImsi(Context context) {
	final TelephonyManager mTelephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
	String imsi = mTelephony.getSubscriberId();
	return imsi;
}