Get IMEI code in Android

Source: Internet
Author: User

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 the Code 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

/** Check whether the ICC card exists */
TM. hasicccard (); // Boolean

/** Roaming:
* (For GSM purposes )*/
TM. isnetworkroaming ();//
}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.