Method instance analysis of TelephonyManager class in Android

  • 2020-08-22 22:41:12
  • OfStack

This article illustrates the methods of the TelephonyManager class in Android. Share to everybody for everybody reference. The details are as follows:

The TelephonyManager class primarily provides a family of get methods for accessing status and information related to cellular communications. This includes the status and information of the SIM mobile phone, the status of the telecom network and the information of mobile phone users. You can use these get methods to get relevant data in your application.

The object of TelephonyManager class can be obtained through Context.getSystemService (Context.es15EN_ES16en) method, it should be noted that some communication information access has a certain limit on the permissions of the application, and the corresponding permissions need to be added at the time of development.

All methods and instructions for the TelephonyManager class are listed below:


package com.ljq.activity;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.CellLocation;
import android.telephony.NeighboringCellInfo;
import android.telephony.TelephonyManager;
public class TelephonyManagerActivity extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    /**
     *  Return to phone status 
     * 
     * CALL_STATE_IDLE  When there is no state  
     * CALL_STATE_OFFHOOK  Pick up the phone 
     * CALL_STATE_RINGING  When the call came in  
     */
    tm.getCallState();
    // Returns the location of the current mobile terminal 
    CellLocation location=tm.getCellLocation();
    // Request a location update. If the update will produce a broadcast, the receiving object is registered LISTEN_CELL_LOCATION Object, required permission The name for ACCESS_COARSE_LOCATION . 
    location.requestLocationUpdate();
    /**
     *  Gets data activity status 
     * 
     * DATA_ACTIVITY_IN  Data connection status: Active, receiving data 
     * DATA_ACTIVITY_OUT  Data connection status: Active, sending data 
     * DATA_ACTIVITY_INOUT  Data connection status: Active, receiving and sending data 
     * DATA_ACTIVITY_NONE  Data connection status: active, but no data sent and received 
     */
    tm.getDataActivity();
    /**
     *  Gets the data connection status 
     * 
     * DATA_CONNECTED  Data connection status: connected 
     * DATA_CONNECTING  Data connection status: being connected 
     * DATA_DISCONNECTED  Data connection status: disconnected 
     * DATA_SUSPENDED  Data connection status: paused 
     */
    tm.getDataState();
    /**
     *  Returns the only for the current mobile terminal 1 logo 
     * 
     *  If it is GSM Network, return IMEI ; If it is CDMA Network, return MEID
     */
    tm.getDeviceId();
    // Return the software version of the mobile terminal, for example: GSM The mobile phone IMEI/SV Code. 
    tm.getDeviceSoftwareVersion();
    // Returns the cell phone number for GSM In network terms MSISDN
    tm.getLine1Number();
    // Returns information about a mobile terminal near the current mobile terminal 
    List<NeighboringCellInfo> infos=tm.getNeighboringCellInfo();
    for(NeighboringCellInfo info:infos){
      // Gets the neighborhood number 
      int cid=info.getCid();
      // Access to neighborhood communities LAC . LAC:  Location area code. In order to determine the location of the moving stations, each GSM/PLMN Is divided into multiple location zones, LAC Is used to identify different location areas. 
      info.getLac();
      info.getNetworkType();
      info.getPsc();
      // Get the signal strength of the neighborhood  
      info.getRssi();
    }
    // return ISO Standard country code, i. e. international code 
    tm.getNetworkCountryIso();
    // return MCC+MNC code  (SIM Card operator country code and operator network code )(IMSI)
    tm.getNetworkOperator();
    // Returns the name of the mobile network operator (SPN)
    tm.getNetworkOperatorName();
    /**
     *  Get network type 
     * 
     * NETWORK_TYPE_CDMA  Network type is CDMA
     * NETWORK_TYPE_EDGE  Network type is EDGE
     * NETWORK_TYPE_EVDO_0  Network type is EVDO0
     * NETWORK_TYPE_EVDO_A  Network type is EVDOA
     * NETWORK_TYPE_GPRS  Network type is GPRS
     * NETWORK_TYPE_HSDPA  Network type is HSDPA
     * NETWORK_TYPE_HSPA  Network type is HSPA
     * NETWORK_TYPE_HSUPA  Network type is HSUPA
     * NETWORK_TYPE_UMTS  Network type is UMTS
     * 
     *  In China, unicom 3G for UMTS or HSDPA , mobile and Unicom 2G for GPRS or EGDE Telecom, 2G for CDMA Telecom, 3G for EVDO
     */
    tm.getNetworkType();
    /**
     *  Returns the type of the mobile terminal 
     * 
     * PHONE_TYPE_CDMA  The standard of mobile phone is CDMA Telecom, 
     * PHONE_TYPE_GSM  The standard of mobile phone is GSM , Mobile and Unicom 
     * PHONE_TYPE_NONE  Mobile phone system unknown 
     */
    tm.getPhoneType();
    // return SIM Country code of the card provider 
    tm.getSimCountryIso();
    // return MCC+MNC code  (SIM Card operator country code and operator network code )(IMSI)
    tm.getSimOperator();
    tm.getSimOperatorName();
    // return SIM The serial number of the card (IMEI)
    tm.getSimSerialNumber();
    /**
     *  Return to mobile terminal 
     * 
     * SIM_STATE_ABSENT SIM Card is not found 
     * SIM_STATE_NETWORK_LOCKED SIM The card network is locked. Need Network PIN unlock 
     * SIM_STATE_PIN_REQUIRED SIM card PIN Locked. Need User PIN unlock 
     * SIM_STATE_PUK_REQUIRED SIM card PUK Locked. Need User PUK unlock 
     * SIM_STATE_READY SIM Card available 
     * SIM_STATE_UNKNOWN SIM Card is unknown 
     */
    tm.getSimState();
    // Return to user only 1 Logos, such as GSM The network IMSI Serial number 
    tm.getSubscriberId();
    // Gets the letter id associated with a voicemail number.  
    tm.getVoiceMailAlphaTag();
    // Return a voicemail number 
    tm.getVoiceMailNumber();
    tm.hasIccCard();
    // Returns whether the phone is roaming 
    tm.isNetworkRoaming();
    // tm.listen(PhoneStateListener listener, int events) ;
    // Explanation: 
    //IMSI Is short for International Mobile User Identification Code (International Mobile Subscriber Identity)
    //IMSI A total of 15 Bit, whose structure is as follows: 
    //MCC+MNC+MIN
    //MCC : Mobile Country Code , mobile country code, total 3 Bit, China is 460;
    //MNC:Mobile NetworkCode , mobile network code, total 2 position 
    // In China, the code for mobile is electricity 00 and 02 , the code of Unicom is 01 , the code of telecom is 03
    // It all adds up to Android In the mobile phone APN Code in configuration file) : 
    // China Mobile: 46000 46002
    // China Unicom: 46001
    // China Telecom: 46003
    // For example, 1 A typical IMSI Number is 460030912121001
    //IMEI is International Mobile Equipment Identity  Short for International Mobile Device Identification 
    //IMEI by 15 Bits and digits form the "electronic string" that connects each cell phone 11 And the code is unique in the world 1 the 
    // Its composition is as follows: 
    //1.  before 6 digits (TAC) It's "Model Approval Number", 1 General representative model 
    //2.  Then the 2 digits (FAC) It's the final assembly number, 1 Generally representing place of origin 
    //3.  After the 6 digits (SNR) It's "string number", 1 Usually represents the production sequence number 
    //4.  The last 1 digits (SP) Usually" 0 "For the purpose of testing code 
  }
}

I hope this article has been helpful in your Android programming.


Related articles: