Question

public String getSubscriberId(){
    operator = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
    String IMSI = operator.getSubscriberId();
    return IMSI;
}

simID = (TextView) findViewById(R.id.text2);
    simIMSI = getSubscriberId().toString();

    if (simIMSI.equals("")){
        simID.setText("No SIM card detected!");
    }
    else{
        simID.setText(simIMSI.toString());
        SaveUniqueId(simIMSI.toString());
    }

I wish to retrieve the phone SIM card IMSI and display in a layout, I run the program using an emulator even though I know emulator does not have SIM card attached but it should have result like "No SIM card detected" right? But why I get error for this coding or is it something wrong in my "getSubscriberId()"?

Was it helpful?

Solution

String serviceName = Context.TELEPHONY_SERVICE;
TelephonyManager m_telephonyManager = (TelephonyManager) getSystemService(serviceName);

Now let's start with actual source code to retrieve the information:-

public String findDeviceID() {
     String deviceID = null;
     String serviceName = Context.TELEPHONY_SERVICE;
     TelephonyManager m_telephonyManager = (TelephonyManager) getSystemService(serviceName);
     int deviceType = m_telephonyManager.getPhoneType();
     switch (deviceType) {
           case (TelephonyManager.PHONE_TYPE_GSM):
           break;
  case (TelephonyManager.PHONE_TYPE_CDMA):
  break;
  case (TelephonyManager.PHONE_TYPE_NONE):
  break;
          default:
         break;
     }
     deviceID = m_telephonyManager.getDeviceId();
     return deviceID;
}

For more details please refer this site http://ashnatechnologies.blogspot.in/2010/10/how-to-get-imei-on-android-devices.html

OTHER TIPS

You can visit this link http://www.anddev.org/tinytut_-_getting_the_imsi_-_imei_sim-device_unique_ids-t446.html

use following code for IMSI

String imsi = android.os.SystemProperties.get(android.telephony.TelephonyProperties.PROPERTY_IMSI);

This code should work.

String myIMSI =
android.os.SystemProperties.get(android.telephony.TelephonyProperties.PROPERTY_IMSI);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top