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

private static String getDeviceId(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String tmDevice = null;//  w ww  .  j a  v a  2 s . c  o m
    String tmSerial = null;
    String androidId = null;
    try {
        tmDevice = tm.getDeviceId();
    } catch (Exception e) {
        Log.w(LOG_TAG, e);
    }
    try {
        tmSerial = tm.getSimSerialNumber();
    } catch (Exception e) {
        Log.w(LOG_TAG, e);
    }
    androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
    if (tmDevice == null) {
        tmDevice = "";
    }
    if (tmSerial == null) {
        tmSerial = "";
    }
    if (androidId == null) {
        androidId = "";
    }
    UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
    return "lsa-kp" + deviceUuid.toString();
}

From source file:Main.java

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;// w w  w.  java  2s . com
}

From source file:Main.java

public static String getDeviceInfo(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    StringBuilder sb = new StringBuilder();
    sb.append("\nDeviceId(IMEI) = " + tm.getDeviceId());
    sb.append("\nDeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion());
    sb.append("\nLine1Number = " + tm.getLine1Number());
    sb.append("\nNetworkCountryIso = " + tm.getNetworkCountryIso());
    sb.append("\nNetworkOperator = " + tm.getNetworkOperator());
    sb.append("\nNetworkOperatorName = " + tm.getNetworkOperatorName());
    sb.append("\nNetworkType = " + tm.getNetworkType());
    sb.append("\nPhoneType = " + tm.getPhoneType());
    sb.append("\nSimCountryIso = " + tm.getSimCountryIso());
    sb.append("\nSimOperator = " + tm.getSimOperator());
    sb.append("\nSimOperatorName = " + tm.getSimOperatorName());
    sb.append("\nSimSerialNumber = " + tm.getSimSerialNumber());
    sb.append("\nSimState = " + tm.getSimState());
    sb.append("\nSubscriberId(IMSI) = " + tm.getSubscriberId());
    sb.append("\nVoiceMailNumber = " + tm.getVoiceMailNumber());

    return sb.toString();
}

From source file:com.phonegap.Device.java

public String getSimSerialNumber() {
    TelephonyManager operator = (TelephonyManager) this.ctx.getSystemService(Context.TELEPHONY_SERVICE);
    return operator.getSimSerialNumber();
}

From source file:org.digitalcampus.oppia.utils.MetaDataUtils.java

public MetaDataUtils(Context ctx) {
    this.ctx = ctx;
    TelephonyManager manager = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
    networkProvider = manager.getNetworkOperatorName();
    deviceId = manager.getDeviceId();// w  w w .jav  a2 s  .c  o  m
    simSerial = manager.getSimSerialNumber();
}

From source file:com.fallahpoor.infocenter.fragments.SimFragment.java

private String getSimSerialNumber(TelephonyManager telephonyManager) {

    String simSerialNumber = telephonyManager.getSimSerialNumber();

    if (Utils.isEmpty(simSerialNumber)) {
        return getString(R.string.unknown);
    } else {// www  .jav  a 2s.  c o m
        return simSerialNumber;
    }

}

From source file:org.hygieiasoft.cordova.uid.UID.java

/**
 * Get the sim's Integrated Circuit Card Identifier (ICCID).
 *
 * @param context The context of the main Activity.
 * @return/* w ww. ja  va  2s.c om*/
 */
public String getIccid(Context context) {
    final TelephonyManager mTelephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String iccid = mTelephony.getSimSerialNumber();
    return iccid;
}

From source file:es.mdelapenya.uned.master.is.ubicomp.sensors.activities.location.BaseGeoLocatedActivity.java

private String getUniqueDeviceId() {
    TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

    final String deviceId = telephonyManager.getDeviceId();
    final String simSerialNumber = telephonyManager.getSimSerialNumber();
    final String androidId = android.provider.Settings.Secure.getString(getContentResolver(),
            android.provider.Settings.Secure.ANDROID_ID);

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

    return deviceUuid.toString();
}

From source file:com.wso2.mobile.mdm.api.DeviceInfo.java

/**
*Returns the SIM serial number/*from w w w.j a  v  a2s. com*/
*/
public String getSimSerialNumber() {
    TelephonyManager telemamanger = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String getSimSerialNumber = telemamanger.getSimSerialNumber();
    return getSimSerialNumber;
}

From source file:au.com.websitemasters.schools.lcps.push.RegistrationIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    try {/*from  w w  w  .jav a2  s .  c  o  m*/
        // [START register_for_gcm]
        // Initially this call goes out to the network to retrieve the token, subsequent calls
        // are local.
        // R.string.gcm_defaultSenderId (the Sender ID) is typically derived from google-services.json.
        // See https://developers.google.com/cloud-messaging/android/start for details on this file.
        // [START get_token]

        InstanceID instanceID = InstanceID.getInstance(this);
        String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
                GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

        String uid;
        try {
            uid = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
        } catch (NullPointerException e) {
            final TelephonyManager tm = (TelephonyManager) getBaseContext()
                    .getSystemService(Context.TELEPHONY_SERVICE);
            final String tmDevice, tmSerial, androidId;
            tmDevice = "" + tm.getDeviceId();
            tmSerial = "" + tm.getSimSerialNumber();
            androidId = "" + android.provider.Settings.Secure.getString(getContentResolver(),
                    android.provider.Settings.Secure.ANDROID_ID);
            UUID deviceUuid = new UUID(androidId.hashCode(),
                    ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
            uid = deviceUuid.toString();
        }

        Log.d("rklogs", "uid: " + uid);
        Log.d("rklogs", "GCM Reg Token: " + token);

        RetrofitClient client = new RetrofitClient();
        client.postToken(token, uid);

        // [END get_token]
        // TODO: Implement this method to send any registration to your app's servers.
        sendRegistrationToServer(token);

        // Subscribe to topic channels
        subscribeTopics(token);

        // You should store a boolean that indicates whether the generated token has been
        // sent to your server. If the boolean is false, send the token to your server,
        // otherwise your server should have already received the token.
        sharedPreferences.edit().putBoolean(getResources().getString(R.string.sent_token_to_server), true)
                .apply();
        // [END register_for_gcm]
    } catch (Exception e) {
        Log.d(TAG, "Failed to complete token refresh", e);
        // If an exception happens while fetching the new token or updating our registration data
        // on a third-party server, this ensures that we'll attempt the update at a later time.
        sharedPreferences.edit().putBoolean(getResources().getString(R.string.sent_token_to_server), false)
                .apply();
    }
    // Notify UI that registration has completed, so the progress indicator can be hidden.
    Intent registrationComplete = new Intent(getResources().getString(R.string.registration_complete));
    LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
}