Wednesday, July 3, 2013

IMEI number of your android device

You may be in a situation where you want to access your device IMEI number. Specially in case where you dont want your application's user to be irritated by enabling him to enter username and password for authentification.

You want to call android.telephony.TelephonyManager.getDeviceId().
This will return whatever string uniquely identifies the device.

You'll need the
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
permission to do this.

Source code to call telephone manager :

 You can get access to various useful information using telephony manager as :
  1. IMEI number
  2. Subscriber ID
  3. SIM state
  4. Is in roaming or not
 You create new instance of telephony manager as :

TelephonyManager mytelemanager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);

1.To get imei number :

String IMEInumber = mytelemanager.getDeviceId();

2. IMEI and subscriber ID are one and the same.

3. SIM state

            int SIMState=mytelemanager.getSimState();
            switch(SIMState)
            {
                    case TelephonyManager.SIM_STATE_ABSENT :
                        Log.d(SIMState,"absent");
                        break;
                    case TelephonyManager.SIM_STATE_NETWORK_LOCKED :
                       
Log.d(SIMState,"network locked");
                        break;
                    case TelephonyManager.SIM_STATE_PIN_REQUIRED :
                       
Log.d(SIMState,"pin required");
                        break;
                    case TelephonyManager.SIM_STATE_PUK_REQUIRED :
                       
Log.d(SIMState,"puk required");
                        break;
                    case TelephonyManager.SIM_STATE_READY :
                       
Log.d(SIMState,"Ready");
                        break;
                    case TelephonyManager.SIM_STATE_UNKNOWN :
                       
Log.d(SIMState,"Unknown");
                        break;
                        }


 4.  Is in Roaming or not
  
      String phoneDetails;
      boolean isRoaming=mytelemanager.isNetworkRoaming();
              if(isRoaming)
                      phoneDetails+="\nIs In Roaming : "+"YES";
              else
                     phoneDetails+="\nIs In Roaming : "+"NO";


No comments:

Post a Comment