`

Getting the IMSI / IMEI (SIM/Device unique IDs)

阅读更多
What you learn:  You will learn how read out the IMSI  (International Mobile Subscriber Identity ) of the SIM-Card present in your mobile and the IMEI (International Mobile Equipment Identity). The IMSI  identifies with the SIM , the IMEI  with the device

Possible Scenario:  You need a unique id  for authentication/registration or license purposes of your Android-Activity Question  This two lines below provide you one SIM-unique ID, the IMSI  and the device-unique ID the IMEI  Exclamation  

Difficulty:  1 of 5 Smile  

Idea  Questions/Problems:  Simply post below... 

Description:  
An International Mobile Subscriber Identity, or IMSI , is a unique number  associated with all GSM and Universal Mobile Telecommunications System (UMTS) network mobile phone users. It is stored  in the Subscriber Identity Module (SIM ) inside the phone and is sent by the phone to the network. It is also used to acquire other details of the mobile in the Home Location Register (HLR ) or as locally copied in the Visitor Location Register. In order to avoid the subscriber being identified and tracked by eavesdroppers on the radio interface, the IMSI  is sent as rarely as possible and a randomly generated TMSI  is sent instead

The International Mobile Equipment Identity or IMEI  is a number unique  to every GSM  and UMTS  mobile phone.It is usually found printed on the phone underneath the battery and can also be found by dialing the sequence *#06#  into the phone.  


Code:  And this is how you read out the unique  IMSI-ID  / IMEI-ID  within Android
Java:
String  myIMSI = android.os .SystemProperties .get ( android.telephony .TelephonyProperties .PROPERTY_IMSI )
// within my emulator it returns:   310995000000000  

String  myIMEI = android.os .SystemProperties .get ( android.telephony .TelephonyProperties .PROPERTY_IMEI )
// within my emulator it returns:   000000000000000

Thats it Smile


The following code is deprecated. 

String myIMSI = android.os.SystemProperties.get(android.telephony.TelephonyProperties.PROPERTY_IMSI); 
// within my emulator it returns: 310995000000000 

String myIMEI = android.os.SystemProperties.get(android.telephony.TelephonyProperties.PROPERTY_IMEI); 
// within my emulator it returns: 000000000000000 

In order to get IMSI and IMEI, the following code works, assuming you write the code in a Activity class. 

TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); 
String imsi = mTelephonyMgr.getSubscriberId(); 
String imei = mTelephonyMgr.getDeviceId(); 

Do not forget to set <uses-permission android:name="android.permission.READ_PHONE_STATE"/> in AndroidManifest.xml.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics