Example usage for android.telephony TelephonyManager getSimSerialNumber

List of usage examples for android.telephony TelephonyManager getSimSerialNumber

Introduction

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

Prototype

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

Source Link

Document

Returns the serial number of the SIM, if applicable.

Usage

From source file:Main.java

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

From source file:Main.java

public static String getIccid(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm == null) {
        return "000000000000000";
    }/*w  w w.j a v a2s .c  o  m*/
    return tm.getSimSerialNumber();
}

From source file:Main.java

private static String generateDeviceUniqueIdentifier(Context context) {
    final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    final String tmDevice = "" + tm.getDeviceId();
    final String tmSerial = "" + tm.getSimSerialNumber();
    final String androidId = ""
            + Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
    final String packageBasedAndroidId = context.getPackageName() + androidId;

    UUID deviceUuid = new UUID(packageBasedAndroidId.hashCode(),
            ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
    return deviceUuid.toString();
}

From source file:Main.java

/**
 * Reads the phone state in order to get SIM serial number and AndroidID, those values are saved in static
 * attributes in this class/*w  w  w  .  j  a v  a2s.  c om*/
 *
 * @param context
 */
public static void readPhoneState(Context context) {

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

    //Get SIM serial number
    SIM_SERIAL_NUMBER = telephonyManager.getSimSerialNumber();
    if (SIM_SERIAL_NUMBER == null) {
        SIM_SERIAL_NUMBER = "";
    }

    /*
     * Settings.Secure.ANDROID_ID returns the unique DeviceID
     * Works for Android 2.2 and above
     */
    ANDROID_ID = getUniqueDeviceId(context);
}

From source file:Main.java

public static String getDeviceKey(Context ctx) {

    final TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
    final String tmDevice, tmSerial, androidId;
    tmDevice = "" + tm.getDeviceId();
    tmSerial = "" + tm.getSimSerialNumber();
    androidId = "" + android.provider.Settings.Secure.getString(ctx.getContentResolver(),
            android.provider.Settings.Secure.ANDROID_ID);
    UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
    return deviceUuid.toString();
}

From source file:Main.java

public static String getDeviceId(Context context) {

    if (deviceId == null) {

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

        String tmDevice, tmSerial, tmPhone, androidId;
        tmDevice = "" + tm.getDeviceId();
        tmSerial = "" + tm.getSimSerialNumber();
        androidId = "" + android.provider.Settings.Secure.getString(context.getContentResolver(),
                android.provider.Settings.Secure.ANDROID_ID);

        UUID deviceUuid = new UUID(androidId.hashCode(),
                ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
        deviceId = deviceUuid.toString();

        System.err.println(deviceId);
    }/*from ww w . ja v a 2  s .c  om*/
    return deviceId;
}

From source file:Main.java

/**
 * this generate the device Id//from  w  w  w .  j  a v a2s .  c  o m
 *
 * @param baseContext
 * @param contentResolver
 * @return
 */
//http://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id
public static String generateDeviceId(Context baseContext, ContentResolver contentResolver) {

    final TelephonyManager tm = (TelephonyManager) baseContext.getSystemService(Context.TELEPHONY_SERVICE);

    final String tmDevice, tmSerial, androidId;
    tmDevice = String.valueOf(tm.getDeviceId());
    tmSerial = String.valueOf(tm.getSimSerialNumber());
    androidId = String.valueOf(android.provider.Settings.Secure.getString(contentResolver,
            android.provider.Settings.Secure.ANDROID_ID));

    UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
    return deviceUuid.toString();

}

From source file:com.njlabs.amrita.aid.util.Identifier.java

@SuppressLint("HardwareIds")
public static String identify(Context context) {
    final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    final String tmDevice, tmSerial, androidId;
    tmDevice = "" + tm.getDeviceId();
    tmSerial = "" + tm.getSimSerialNumber();
    androidId = "" + android.provider.Settings.Secure.getString(context.getContentResolver(),
            android.provider.Settings.Secure.ANDROID_ID);

    UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
    return deviceUuid.toString();
}

From source file:Main.java

public static String getDeviceUUID(Context context) {

    @SuppressWarnings("static-access")
    final TelephonyManager tm = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE);

    final String tmDevice, tmSerial, tmPhone, androidId;

    tmDevice = "" + tm.getDeviceId();

    tmSerial = "" + tm.getSimSerialNumber();

    androidId = "" + android.provider.Settings.Secure.getString(context.getContentResolver(),
            android.provider.Settings.Secure.ANDROID_ID);

    UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());

    String uniqueId = deviceUuid.toString();

    Log.d("debug", "uuid=" + uniqueId);

    return uniqueId;
}

From source file:Main.java

public static String get_device_id(Context ctx) {

    final TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);

    String tmDevice = "";
    String tmSerial = null;/*from ww w.jav  a2  s  .  c o m*/
    String androidId = null;

    try {
        tmDevice = "" + tm.getDeviceId();
    } catch (Exception ex) {
    }

    try {
        tmSerial = "" + tm.getSimSerialNumber();
    } catch (Exception ex) {
    }
    try {
        androidId = "" + android.provider.Settings.Secure.getString(ctx.getContentResolver(),
                android.provider.Settings.Secure.ANDROID_ID);
    } catch (Exception ex) {
    }
    try {
        UUID deviceUuid = new UUID(androidId.hashCode(),
                ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
        String deviceId = deviceUuid.toString();

        MessageDigest md = MessageDigest.getInstance("SHA-256");
        md.update(deviceId.getBytes());

        byte byteData[] = md.digest();

        //convert the byte to hex format method 1
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < byteData.length; i++) {
            sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
        }
        deviceId = sb.toString();

        return deviceId;
    } catch (Exception ex) {
    }
    return "nodeviceid";
}