Example usage for android.telephony TelephonyManager getSubscriberId

List of usage examples for android.telephony TelephonyManager getSubscriberId

Introduction

In this page you can find the example usage for android.telephony TelephonyManager getSubscriberId.

Prototype

@SuppressAutoDoc 
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public String getSubscriberId() 

Source Link

Document

Returns the unique subscriber ID, for example, the IMSI for a GSM phone.

Usage

From source file:Main.java

/**
 * Get phone service provider/*from   w  w w .  j av  a2s.  c  o  m*/
 *
 * @param context Context
 * @return 10086 10010 10000
 */
public static String getPhoneServiceProvider(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String id = tm.getSubscriberId();
    if (id == null) {
        return null;
    }
    if (id.startsWith("46000") || id.startsWith("46002")) {
        return "10086";
    }
    if (id.startsWith("46001")) {
        return "10010";
    }
    if (id.startsWith("46003")) {
        return "10000";
    }
    return null;
}

From source file:Main.java

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;
    }/* w  w w.j  a v  a  2 s . c  o m*/
    return PROVIDER_UNKNOWN;
}

From source file:Main.java

public static String getIMSI(Context context) {
    TelephonyManager manager = (TelephonyManager) context.getApplicationContext()
            .getSystemService(Context.TELEPHONY_SERVICE);
    return manager.getSubscriberId();
}

From source file:Main.java

public static String getIMSI(Context context) {
    String imsi = "";
    try {/*w ww. ja  v a  2s. c  o  m*/
        TelephonyManager phoneManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        imsi = phoneManager.getSubscriberId();
        Log.v(TAG, imsi);
    } catch (Exception e) {
        Log.e(TAG, "getIMSI error!");
        imsi = "";
    }

    if (imsi == null) {
        imsi = "";
    }
    return imsi;
}

From source file:Main.java

public static String getImsi(Context context) {
    TelephonyManager mTelephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String imsi = mTelephonyMgr.getSubscriberId();
    return imsi;/*  w w w .  j  a  v a 2s  . co m*/
}

From source file:Main.java

public static String getDeviceId(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String deviceId = tm.getDeviceId();
    if (deviceId == null) {
        deviceId = tm.getSubscriberId();
    }/*w w w.  j  av  a  2  s.c  o m*/
    return deviceId;
}

From source file:Main.java

public static String getIMSI(Context context) {
    Object objTemp = context.getSystemService(Context.TELEPHONY_SERVICE);
    TelephonyManager phoneMgr;
    String imsi = "";
    if (objTemp != null && objTemp instanceof TelephonyManager) {
        phoneMgr = (TelephonyManager) objTemp;
        imsi = phoneMgr.getSubscriberId();
    }/*  w ww .  j  av a2  s  .  c o  m*/
    return imsi;
}

From source file:Main.java

public static String getDeviceImsi(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm == null) {
        return "null";
    } else {/*from  w w w.  j  a v a2 s . com*/
        String id = tm.getSubscriberId();
        return id == null ? "null" : id;
    }
}

From source file:crow.util.Util.java

/**
 * ???? ?manifest ?? <uses-permission
 * android:name="android.permission.READ_PHONE_STATE">
 * /*  w  ww .  jav a  2  s .c  o m*/
 * @param context
 * @return "" / "?" / "" / ""
 */
public static String getCarrier(Context context) {
    TelephonyManager telManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String imsi = telManager.getSubscriberId();
    if (imsi != null && !"".equals(imsi)) {
        if (imsi.startsWith("46000") || imsi.startsWith("46002")) {// ?46000IMSI?46002?134/159??
            return "";
        } else if (imsi.startsWith("46001")) {
            return "?";
        } else if (imsi.startsWith("46003")) {
            return "";
        }
    }
    return "";
}

From source file:Main.java

public static String getDeviceId(Context ctx) {
    StringBuilder sbuff = new StringBuilder();
    TelephonyManager telephonyManager = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);

    /*//from ww w  .jav  a 2s .  c om
     * getDeviceId() function Returns the unique device ID.
     * for example,the IMEI for GSM and the MEID or ESN for CDMA phones.
     */
    String imeistring = telephonyManager.getDeviceId();
    sbuff.append(imeistring + DELIMITER);

    /*
     * getSubscriberId() function Returns the unique subscriber ID,
     * for example, the IMSI for a GSM phone.
     */
    String imsistring = telephonyManager.getSubscriberId();
    sbuff.append(imsistring + DELIMITER);

    /*
     * Settings.Secure.ANDROID_ID returns the unique DeviceID
     * Works for Android 2.2 and above
     */
    String androidId = Settings.Secure.getString(ctx.getContentResolver(), Settings.Secure.ANDROID_ID);
    sbuff.append(androidId);
    //Log.d("deep link device id", sbuff.toString()+"");
    return (sbuff.toString());
}