Use of the Android Telephonymanager class

Source: Internet
Author: User

The Telephonymanager class mainly provides a series of get methods to get the status and information related to the mobile phone, including the information of the mobile phone user, the status of the Sim, and the status of the telecommunication network.
Gets the object of the Telephonymanager class:

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

In the development of the time do not forget to add the appropriate permissions in the configuration file Oh

<!--同意读取电话状态SIM的权限-->    <uses-permission android:name="android.permission.READ_PHONE_STATE" />    <!-- 这个权限用于进行网络定位 -->    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

Here are some simple ways to list the Telephonymanager class

 PackageCom.xiaolijuan.getphoneinfo;Importandroid.app.Activity;ImportAndroid.content.Context;ImportAndroid.os.Bundle;ImportAndroid.telephony.NeighboringCellInfo;ImportAndroid.telephony.TelephonyManager;ImportAndroid.widget.TextView;ImportJava.util.List; Public  class mainactivity extends Activity {    PrivateTelephonymanager TM =NULL;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (R.layout.activity_main);        TM = (Telephonymanager) getsystemservice (Context.telephony_service); Telephonymanager TM = (Telephonymanager) getsystemservice (Context.telephony_service);/** * Get the location of the current device * /Tm.getcelllocation (). toString ();/** * Get Data Connection Status * * data_connected data Connection Status: Connected * data_connecting data connection Status: Connecting * D ata_disconnected Data Connection Status: Disconnect * data_suspended data Connection Status: Paused */Tm.getdatastate ();/** * Returns a unique Device ID * assumed to be a GSM network. Returns the IMEI, assuming it is a CDMA network. Returns the Meid, assuming that the device ID is not available return null * /Tm.getdeviceid ();/** * Returns the software version number of the device * For example: GSM mobile phone IMEI/SV code. Assume that the software version number returns NULL. Null is assumed to be unavailable * /Tm.getdevicesoftwareversion ();/** * Return mobile number * MSISDN for GSM network, assuming not available return null */Tm.getline1number ();/** * Returns information for devices near the current device */list<neighboringcellinfo> infos = Tm.getneighboringcellinfo (); for(Neighboringcellinfo Info:infos) {//Get neighbor cell number            intCID = Info.getcid ();Get neighbor Cell Lac,lac: Location bar code.

To determine the location of the mobile station, each GSM/PLMN area is divided into a number of location areas, and the LAC is used to identify different locations.Info.getlac (); Info.getnetworktype (); INFO.GETPSC ();//Get neighbor cell signal strengthInfo.getrssi (); }/** * Return to the ISO standard country code, which is the international calling code */Tm.getnetworkcountryiso ();/** * Return MCC+MNC code (SIM card carrier country code and carrier Network Code) (IMSI) */Tm.getnetworkoperator ();/** * Returns the name of the mobile network operator (SPN) */Tm.getnetworkoperatorname ();/** * Get network type * * NETWORK_TYPE_CDMA network type for CDMA * Network_type_edge network type for EDGE * N ETWORK_TYPE_EVDO_0 network type is EVDO0 * network_type_evdo_a network type is EVDOA * Network_type_gprs network type is GPRS * NET WORK_TYPE_HSDPA network type is HSDPA * Network_type_hspa network type is HSPA * Network_type_hsupa network type is HSUPA * Net _TYPE_UMTS network type is UMTS * * in China, Unicom's 3G is UMTS or HSDPA, mobile and Unicom 2G for GPRS or EGDE, telecommunications 2G for CDMA. The 3G of Telecom is EVDO * /Tm.getnetworktype ();/** * return Device type * * PHONE_TYPE_CDMA mobile phone system for CDMA, telecommunications * PHONE_TYPE_GSM mobile phone format for GSM, Mobile and Unicom * Phone_type_none Phone format unknown * *Tm.getphonetype ();/** * Return the country code of the SIM card provider * *Tm.getsimcountryiso ();/** * Return MCC+MNC code (SIM card carrier country code and carrier Network Code) (IMSI) */Tm.getsimoperator ();/** * Returns the name of the service provider (SPN) */Tm.getsimoperatorname ();/** * Returns the serial number (IMEI) of the SIM card, assuming that null is returned as unavailable. */Tm.getsimserialnumber ();/** * Returns a constant indicating the status of the default SIM card. * * Sim_state_absent SIM card not found * sim_state_network_locked SIM card Network is locked and needs to be unlocked by the net PIN * sim_state_pin_ REQUIRED SIM pin is locked and requires user pin to unlock * sim_state_puk_required sim PUK is locked. User PUK is required to unlock * Sim_state_ready SIM card available * Sim_state_unknown sim unknown */Tm.getsimstate ();/** * Returns a unique user ID, for example, IMSI GSM phone.

*/Tm.getsubscriberid ();/** * Get the letter ID associated with the voicemail number */Tm.getvoicemailalphatag ();/** * return voice mail number */Tm.getvoicemailnumber ();/** * Returns whether the phone is roaming */Tm.isnetworkroaming (); ((TextView) Findviewbyid (R.id.tv_info)). SetText (GetInfo ()); } PublicStringGetInfo() {String info ="Get device number:"+ Tm.getdeviceid (); Info + ="\ nthe country code for the SIM card provider:"+ Tm.getsimcountryiso (); Info + ="\ n get SIM card serial number:"+ Tm.getsimserialnumber (); Info + ="\ n Get network Operator code:"+ Tm.getnetworkoperator (); Info + ="\ n Get network operator name:"+ Tm.getnetworkoperatorname (); Info + ="\ n get the device's current location:"+ tm.getcelllocation (); Info + ="\ n Get phone type:"+ Tm.getphonetype (); Info + ="\ n phone Number:"+ Tm.getline1number (); Info + ="\ n International calling code:"+ Tm.getnetworkcountryiso (); Info + ="\ nthe get network type:"+ Tm.getnetworktype (); Info + ="\ n Get Data Connection status:"+ tm.getdatastate ();returnInfo }}

Here are some explanations:
(1) IMSI is the abbreviation for the International Mobile Subscriber Identification Code (International Mobile Subscriber Identity)
IMSI co-owned 15. Its structure is as follows:
Mcc+mnc+min
Mcc:mobile Country Code. Mobile Country Code, a total of 3 people, China is 460;
Mnc:mobile Networkcode. Mobile network Code. Total 2 Guests
In China, the code for Mobile is 00 and 02, the code for Unicom is 01, and the code for telecommunications is 03.
The combination is (also the code in the APN configuration file on the Android phone):
China Mobile: 46000 46002
China Unicom: 46001
China Telecom: 46003

(2) IMEI is the abbreviation for International Mobile Equipment identity (International mobile device identity)
The IMEI consists of a 15-digit "electronic serial number", which corresponds to one by one of each phone. And the code is the only one in the world
Its composition is:
1. The first 6 digits (TAC) is the "Model approval number", the general representative of the model
2. The next 2-digit (FAC) is the "final assembly number". General Representative Origin
3. The subsequent 6-digit (SNR) is the "serial number". General representative production sequence number
4. The last 1 digits (SP) are generally "0″, for the inspection code." Right now, standby.

References: http://www.cnblogs.com/linjiqin/archive/2011/02/26/1965682.html

Use of the Android Telephonymanager class

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.