The method in Android to obtain the IMEI code

  • 2020-05-10 18:48:04
  • OfStack

Core code:
Imei = ((TelephonyManager) getSystemService(TELEPHONY_SERVICE))
.getDeviceId();
1. Add permissions
In the manifest.xml file to add < uses-permission android:name="android.permission.READ_PHONE_STATE" / >
Code 2.

package net.sunniwell.app;     
import android.app.Activity;     
import android.os.Bundle;     
import android.telephony.CellLocation;     
import android.telephony.PhoneStateListener;     
import android.telephony.TelephonyManager;     
public class TelManager extends Activity {     

@Override    
protected void onCreate(Bundle savedInstanceState) {     
  super.onCreate(savedInstanceState);     
  TelephonyManager tm = (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE);     

  /*   
   *  Telephone status:    
   * 1.tm.CALL_STATE_IDLE=0           There is no activity    
   * 2.tm.CALL_STATE_RINGING=1   Ring the bell    
   * 3.tm.CALL_STATE_OFFHOOK=2   Picking machine    
   */    
  tm.getCallState();//int     

  /*   
   *  Telephone location:    
   *    
   */    
  tm.getCellLocation();//CellLocation     

  /*   
   *  only 1 The equipment ID :    
   * GSM The mobile phone  IMEI  and  CDMA The mobile phone  MEID.    
   * Return null if device ID is not available.   
   */    
  tm.getDeviceId();//String     

  /*   
   *  Software version number of the device:    
   *  Such as: the IMEI/SV(software version) for GSM phones.   
   * Return null if the software version is not available.    
   */    
  tm.getDeviceSoftwareVersion();//String     

  /*   
   *  Mobile phone no. :    
   * GSM The mobile phone  MSISDN.   
   * Return null if it is unavailable.    
   */    
  tm.getLine1Number();//String     

  /*   
   *  A message about a nearby phone :   
   *  Type: List<NeighboringCellInfo>    
   *  Required permissions: android.Manifest.permission#ACCESS_COARSE_UPDATES   
   */    
  tm.getNeighboringCellInfo();//List<NeighboringCellInfo>     

  /*   
   *  To obtain ISO The standard country code, that is, the international distance code.    
   *  Note: only valid if the user has already registered on the network.    
   *        in CDMA The results in the network may not be reliable.    
   */    
  tm.getNetworkCountryIso();//String     

  /*   
   * MCC+MNC(mobile country code + mobile network code)   
   *  Note: only valid if the user is already registered on the network.    
   *     in CDMA The results in the network may not be reliable.    
   */    
  tm.getNetworkOperator();//String     

  /*   
   *  In alphabetical order current registered operator( Current registered user ) The name of the    
   *  Note: only valid if the user is already registered on the network.    
   *     in CDMA The results in the network may not be reliable.    
   */    
  tm.getNetworkOperatorName();//String     

  /*   
   *  Network type currently in use:    
   *  Such as:  NETWORK_TYPE_UNKNOWN   Network type unknown   0   
     NETWORK_TYPE_GPRS     GPRS network   1   
     NETWORK_TYPE_EDGE     EDGE network   2   
     NETWORK_TYPE_UMTS     UMTS network   3   
     NETWORK_TYPE_HSDPA    HSDPA network   8    
     NETWORK_TYPE_HSUPA    HSUPA network   9   
     NETWORK_TYPE_HSPA     HSPA network   10   
     NETWORK_TYPE_CDMA     CDMA network ,IS95A  or  IS95B.  4   
     NETWORK_TYPE_EVDO_0   EVDO network , revision 0.  5   
     NETWORK_TYPE_EVDO_A   EVDO network , revision A.  6   
     NETWORK_TYPE_1xRTT    1xRTT network   7   
   */    
  tm.getNetworkType();//int     

  /*   
   *  Mobile phone type:    
   *  Such as:  PHONE_TYPE_NONE   No signal    
     PHONE_TYPE_GSM   GSM signal    
     PHONE_TYPE_CDMA  CDMA signal    
   */    
  tm.getPhoneType();//int     

  /*   
   * Returns the ISO country code equivalent for the SIM provider's country code.   
   *  To obtain ISO Country code, equivalent to provide SIM The country code of the card.    
   *    
   */    
  tm.getSimCountryIso();//String     

  /*   
   * Returns the MCC+MNC (mobile country code + mobile network code) of the provider of the SIM. 5 or 6 decimal digits.   
   *  To obtain SIM Card provides mobile country code and mobile network code .5 or 6 bit 10 Hexadecimal Numbers .   
   * SIM The status of the card must be  SIM_STATE_READY( use getSimState() judge ).   
   */    
  tm.getSimOperator();//String     

  /*   
   *  Service provider name:    
   *  For example: China mobile, China unicom    
   * SIM The status of the card must be  SIM_STATE_READY( use getSimState() judge ).   
   */    
  tm.getSimOperatorName();//String     

  /*   
   * SIM Card serial number:    
   *  Required permissions: READ_PHONE_STATE   
   */    
  tm.getSimSerialNumber();//String     

  /*   
   * SIM Status information:    
   *  SIM_STATE_UNKNOWN           An unknown state  0   
   SIM_STATE_ABSENT            No card  1   
   SIM_STATE_PIN_REQUIRED      Locked state, user required PIN Code to unlock  2   
   SIM_STATE_PUK_REQUIRED      Locked state, user required PUK Code to unlock  3   
   SIM_STATE_NETWORK_LOCKED    Locked state, need network PIN Code to unlock  4   
   SIM_STATE_READY             The ready state  5   
   */    
  tm.getSimState();//int     

  /*   
   *  only 1 The user ID :    
   *  Such as: IMSI( International mobile user id ) for a GSM phone.   
   *  Required permissions: READ_PHONE_STATE   
   */    
  tm.getSubscriberId();//String     

  /*   
   *  Gets the tag associated with the voice mail, which is an identifier    
   *  Required permissions: READ_PHONE_STATE   
   */    
  tm.getVoiceMailAlphaTag();//String     

  /*   
   *  Get voice mail number:    
   *  Required permissions: READ_PHONE_STATE   
   */    
  tm.getVoiceMailNumber();//String     

  /*   
   * ICC Does the card exist?    
   */    
  tm.hasIccCard();//boolean     

  /*   
   *  If roaming :   
   * ( in GSM Use the )   
   */    
  tm.isNetworkRoaming();//     

       

}     

    
}   


Related articles: