Core code:
Imei = (TelephonyManager) getSystemService (TELEPHONY_SERVICE ))
. GetDeviceId ();
1. Add Permissions
In the manifest. xml file, add <uses-permission android: name = "android. permission. READ_PHONE_STATE"/>
2. Code
Copy codeThe Code is as follows: 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 );
/*
* Phone status:
* 1. tm. CALL_STATE_IDLE = 0 no activity
* 2. tm. CALL_STATE_RINGING = 1 bell
* 3. tm. CALL_STATE_OFFHOOK = 2 disconnect
*/
Tm. getCallState (); // int
/*
* Phone location:
*
*/
Tm. getCellLocation (); // CellLocation
/*
* Unique device ID:
* The IMEI of the GSM mobile phone and the MEID of the CDMA mobile phone.
* Return null if device ID is not available.
*/
Tm. getDeviceId (); // String
/*
* Software version number of the device:
* For example, the IMEI/SV (software version) for GSM phones.
* Return null if the software version is not available.
*/
Tm. getDeviceSoftwareVersion (); // String
/*
* Mobile phone number:
* MSISDN of the GSM mobile phone.
* Return null if it is unavailable.
*/
Tm. getLine1Number (); // String
/*
* Nearby phone information:
* Type: List <NeighboringCellInfo>
* Permission required: android. Manifest. permission # ACCESS_COARSE_UPDATES
*/
Tm. getNeighboringCellInfo (); // List <NeighboringCellInfo>
/*
* Obtain the ISO Standard Country Code, that is, the international long-distance area code.
* Note: it is valid only after the user has registered the network.
* The results may be unreliable in CDMA networks.
*/
Tm. getNetworkCountryIso (); // String
/*
* MCC + MNC (mobile country code + mobile network code)
* Note: it is valid only when the user has registered the network.
* The results may be unreliable in CDMA networks.
*/
Tm. getNetworkOperator (); // String
/*
* The Name Of The current registered operator (currently registered user) in alphabetical order
* Note: it is valid only when the user has registered the network.
* The results may be unreliable in CDMA networks.
*/
Tm. getNetworkOperatorName (); // String
/*
* Current network type:
* For example, The NETWORK_TYPE_UNKNOWN network type is unknown. 0
NETWORK_TYPE_GPRS GPRS network 1
NETWORK_TYPE_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 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:
* For example, PHONE_TYPE_NONE has no signal.
PHONE_TYPE_GSM GSM Signal
PHONE_TYPE_CDMA Signal
*/
Tm. getPhoneType (); // int
/*
* Returns the ISO country code equivalent for the SIM provider's country code.
* Obtain the ISO country code, which is equivalent to the Country Code that provides the SIM 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.
* Obtain the mobile country code and mobile network code. 5 or 6-digit decimal number provided by the SIM card.
* The SIM card status must be SIM_STATE_READY (determined by getSimState ).
*/
Tm. getSimOperator (); // String
/*
* Service provider name:
* For example, China Mobile and China Unicom
* The SIM card status must be SIM_STATE_READY (determined by getSimState ).
*/
Tm. getSimOperatorName (); // String
/*
* Sim card serial number:
* Permission required: READ_PHONE_STATE
*/
Tm. getSimSerialNumber (); // String
/*
* SIM status information:
* SIM_STATE_UNKNOWN unknown status 0
SIM_STATE_ABSENT no card 1
SIM_STATE_PIN_REQUIRED lock status, which requires the user's PIN code to be unlocked 2
SIM_STATE_PUK_REQUIRED lock status, which requires the user's pukcode to be unlocked 3
SIM_STATE_NETWORK_LOCKED lock status, which requires the network PIN to be unlocked 4
SIM_STATE_READY ready status 5
*/
Tm. getSimState (); // int
/*
* Unique User ID:
* For example, IMSI (International Mobile User Identification Code) for a GSM phone.
* Permission required: READ_PHONE_STATE
*/
Tm. getSubscriberId (); // String
/*
* Obtain the tags related to the voice mail, that is, the identifier.
* Permission required: READ_PHONE_STATE
*/
Tm. getVoiceMailAlphaTag (); // String
/*
* Obtain the voice mail Number:
* Permission required: READ_PHONE_STATE
*/
Tm. getVoiceMailNumber (); // String
/*
* Whether the ICC card exists
*/
Tm. hasIccCard (); // boolean
/*
* Roaming or not:
* (For GSM purposes)
*/
Tm. isNetworkRoaming ();//
}
}