public class TelephonyManager extends Object
You do not instantiate this class directly; instead, you retrieve
a reference to an instance through
Context.getSystemService(Context.TELEPHONY_SERVICE)
.
Note that access to some telephony information is permission-protected. Your application cannot access the protected information unless it has the appropriate permissions declared in its manifest file. Where permissions apply, they are noted in the the methods through which you access the protected information.
Modifier and Type | Field and Description |
---|---|
static String |
ACTION_PHONE_STATE_CHANGED
Broadcast intent action indicating that the call state (cellular)
on the device has changed.
|
static int |
CALL_STATE_IDLE
Device call state: No activity.
|
static int |
CALL_STATE_OFFHOOK
Device call state: Off-hook.
|
static int |
CALL_STATE_RINGING
Device call state: Ringing.
|
static int |
DATA_ACTIVITY_DORMANT
Data connection is active, but physical link is down
|
static int |
DATA_ACTIVITY_IN
Data connection activity: Currently receiving IP PPP traffic.
|
static int |
DATA_ACTIVITY_INOUT
Data connection activity: Currently both sending and receiving
IP PPP traffic.
|
static int |
DATA_ACTIVITY_NONE
Data connection activity: No traffic.
|
static int |
DATA_ACTIVITY_OUT
Data connection activity: Currently sending IP PPP traffic.
|
static int |
DATA_CONNECTED
Data connection state: Connected.
|
static int |
DATA_CONNECTING
Data connection state: Currently setting up a data connection.
|
static int |
DATA_DISCONNECTED
Data connection state: Disconnected.
|
static int |
DATA_SUSPENDED
Data connection state: Suspended.
|
static int |
DATA_UNKNOWN
Data connection state: Unknown.
|
static String |
EXTRA_INCOMING_NUMBER
The lookup key used with the
ACTION_PHONE_STATE_CHANGED broadcast
for a String containing the incoming phone number. |
static String |
EXTRA_STATE
The lookup key used with the
ACTION_PHONE_STATE_CHANGED broadcast
for a String containing the new call state. |
static String |
EXTRA_STATE_IDLE
Value used with
EXTRA_STATE corresponding to
CALL_STATE_IDLE . |
static String |
EXTRA_STATE_OFFHOOK
Value used with
EXTRA_STATE corresponding to
CALL_STATE_OFFHOOK . |
static String |
EXTRA_STATE_RINGING
Value used with
EXTRA_STATE corresponding to
CALL_STATE_RINGING . |
static int |
NETWORK_CLASS_2_G
Class of broadly defined "2G" networks.
|
static int |
NETWORK_CLASS_3_G
Class of broadly defined "3G" networks.
|
static int |
NETWORK_CLASS_4_G
Class of broadly defined "4G" networks.
|
static int |
NETWORK_CLASS_UNKNOWN
Unknown network class.
|
static int |
NETWORK_TYPE_1xRTT
Current network is 1xRTT
|
static int |
NETWORK_TYPE_CDMA
Current network is CDMA: Either IS95A or IS95B
|
static int |
NETWORK_TYPE_EDGE
Current network is EDGE
|
static int |
NETWORK_TYPE_EHRPD
Current network is eHRPD
|
static int |
NETWORK_TYPE_EVDO_0
Current network is EVDO revision 0
|
static int |
NETWORK_TYPE_EVDO_A
Current network is EVDO revision A
|
static int |
NETWORK_TYPE_EVDO_B
Current network is EVDO revision B
|
static int |
NETWORK_TYPE_GPRS
Current network is GPRS
|
static int |
NETWORK_TYPE_HSDPA
Current network is HSDPA
|
static int |
NETWORK_TYPE_HSPA
Current network is HSPA
|
static int |
NETWORK_TYPE_HSPAP
Current network is HSPA+
|
static int |
NETWORK_TYPE_HSUPA
Current network is HSUPA
|
static int |
NETWORK_TYPE_IDEN
Current network is iDen
|
static int |
NETWORK_TYPE_LTE
Current network is LTE
|
static int |
NETWORK_TYPE_UMTS
Current network is UMTS
|
static int |
NETWORK_TYPE_UNKNOWN
Network type is unknown
|
static int |
PHONE_TYPE_CDMA
Phone radio is CDMA.
|
static int |
PHONE_TYPE_GSM
Phone radio is GSM.
|
static int |
PHONE_TYPE_NONE
No phone radio.
|
static int |
PHONE_TYPE_SIP
Phone is via SIP.
|
static int |
SIM_STATE_ABSENT
SIM card state: no SIM card is available in the device
|
static int |
SIM_STATE_NETWORK_LOCKED
SIM card state: Locked: requries a network PIN to unlock
|
static int |
SIM_STATE_PIN_REQUIRED
SIM card state: Locked: requires the user's SIM PIN to unlock
|
static int |
SIM_STATE_PUK_REQUIRED
SIM card state: Locked: requires the user's SIM PUK to unlock
|
static int |
SIM_STATE_READY
SIM card state: Ready
|
static int |
SIM_STATE_UNKNOWN
SIM card state: Unknown.
|
Constructor and Description |
---|
TelephonyManager(Context context) |
Modifier and Type | Method and Description |
---|---|
void |
disableLocationUpdates()
Disables location update notifications.
|
void |
enableLocationUpdates()
Enables location update notifications.
|
static TelephonyManager |
from(Context context) |
List<CellInfo> |
getAllCellInfo()
Returns all observed cell information of the device.
|
int |
getCallState()
Returns a constant indicating the call state (cellular) on the device.
|
int |
getCdmaEriIconIndex()
Returns the CDMA ERI icon index to display
|
int |
getCdmaEriIconMode()
Returns the CDMA ERI icon mode,
0 - ON
1 - FLASHING
|
String |
getCdmaEriText()
Returns the CDMA ERI text,
|
CellLocation |
getCellLocation()
Returns the current location of the device.
|
String |
getCompleteVoiceMailNumber()
Returns the complete voice mail number.
|
int |
getCurrentPhoneType()
Returns the current phone type.
|
int |
getDataActivity()
Returns a constant indicating the type of activity on a data connection
(cellular).
|
int |
getDataState()
Returns a constant indicating the current data connection state
(cellular).
|
static TelephonyManager |
getDefault() |
String |
getDeviceId()
Returns the unique device ID, for example, the IMEI for GSM and the MEID
or ESN for CDMA phones.
|
String |
getDeviceSoftwareVersion()
Returns the software version number for the device, for example,
the IMEI/SV for GSM phones.
|
String |
getIsimDomain()
Returns the IMS home network domain name that was loaded from the ISIM.
|
String |
getIsimImpi()
Returns the IMS private user identity (IMPI) that was loaded from the ISIM.
|
String[] |
getIsimImpu()
Returns the IMS public user identities (IMPU) that were loaded from the ISIM.
|
String |
getLine1AlphaTag()
Returns the alphabetic identifier associated with the line 1 number.
|
String |
getLine1Number()
Returns the phone number string for line 1, for example, the MSISDN
for a GSM phone.
|
int |
getLteOnCdmaMode()
Return if the current radio is LTE on CDMA.
|
static int |
getLteOnCdmaModeStatic()
Return if the current radio is LTE on CDMA.
|
String |
getMsisdn()
Returns the MSISDN string.
|
List<NeighboringCellInfo> |
getNeighboringCellInfo()
Returns the neighboring cell information of the device.
|
static int |
getNetworkClass(int networkType)
Return general class of network type, such as "3G" or "4G".
|
String |
getNetworkCountryIso()
Returns the ISO country code equivalent of the current registered
operator's MCC (Mobile Country Code).
|
String |
getNetworkOperator()
Returns the numeric name (MCC+MNC) of current registered operator.
|
String |
getNetworkOperatorName()
Returns the alphabetic name of current registered operator.
|
int |
getNetworkType()
Returns a constant indicating the radio technology (network type)
currently in use on the device for data transmission.
|
String |
getNetworkTypeName()
Returns a string representation of the radio technology (network type)
currently in use on the device.
|
static String |
getNetworkTypeName(int type) |
int |
getPhoneType()
Returns a constant indicating the device phone type.
|
static int |
getPhoneType(int networkMode)
This function returns the type of the phone, depending
on the network mode.
|
String |
getSimCountryIso()
Returns the ISO country code equivalent for the SIM provider's country code.
|
String |
getSimOperator()
Returns the MCC+MNC (mobile country code + mobile network code) of the
provider of the SIM.
|
String |
getSimOperatorName()
Returns the Service Provider Name (SPN).
|
String |
getSimSerialNumber()
Returns the serial number of the SIM, if applicable.
|
int |
getSimState()
Returns a constant indicating the state of the
device SIM card.
|
String |
getSubscriberId()
Returns the unique subscriber ID, for example, the IMSI for a GSM phone.
|
String |
getVoiceMailAlphaTag()
Retrieves the alphabetic identifier associated with the voice
mail number.
|
String |
getVoiceMailNumber()
Returns the voice mail number.
|
int |
getVoiceMessageCount()
Returns the voice mail count.
|
boolean |
hasIccCard() |
boolean |
isNetworkRoaming()
Returns true if the device is considered roaming on the current
network, for GSM purposes.
|
boolean |
isSmsCapable() |
boolean |
isVoiceCapable() |
void |
listen(PhoneStateListener listener,
int events)
Registers a listener object to receive notification of changes
in specified telephony states.
|
public static final String ACTION_PHONE_STATE_CHANGED
The EXTRA_STATE
extra indicates the new call state.
If the new state is RINGING, a second extra
EXTRA_INCOMING_NUMBER
provides the incoming phone number as
a String.
Requires the READ_PHONE_STATE permission.
This was a sticky
broadcast in version 1.0, but it is no longer sticky.
Instead, use getCallState()
to synchronously query the current call state.
public static final String EXTRA_STATE
ACTION_PHONE_STATE_CHANGED
broadcast
for a String containing the new call state.public static final String EXTRA_STATE_IDLE
EXTRA_STATE
corresponding to
CALL_STATE_IDLE
.public static final String EXTRA_STATE_RINGING
EXTRA_STATE
corresponding to
CALL_STATE_RINGING
.public static final String EXTRA_STATE_OFFHOOK
EXTRA_STATE
corresponding to
CALL_STATE_OFFHOOK
.public static final String EXTRA_INCOMING_NUMBER
ACTION_PHONE_STATE_CHANGED
broadcast
for a String containing the incoming phone number.
Only valid when the new call state is RINGING.
Retrieve with
Intent.getStringExtra(String)
.
public static final int PHONE_TYPE_NONE
public static final int PHONE_TYPE_GSM
public static final int PHONE_TYPE_CDMA
public static final int PHONE_TYPE_SIP
public static final int NETWORK_TYPE_UNKNOWN
public static final int NETWORK_TYPE_GPRS
public static final int NETWORK_TYPE_EDGE
public static final int NETWORK_TYPE_UMTS
public static final int NETWORK_TYPE_CDMA
public static final int NETWORK_TYPE_EVDO_0
public static final int NETWORK_TYPE_EVDO_A
public static final int NETWORK_TYPE_1xRTT
public static final int NETWORK_TYPE_HSDPA
public static final int NETWORK_TYPE_HSUPA
public static final int NETWORK_TYPE_HSPA
public static final int NETWORK_TYPE_IDEN
public static final int NETWORK_TYPE_EVDO_B
public static final int NETWORK_TYPE_LTE
public static final int NETWORK_TYPE_EHRPD
public static final int NETWORK_TYPE_HSPAP
public static final int NETWORK_CLASS_UNKNOWN
public static final int NETWORK_CLASS_2_G
public static final int NETWORK_CLASS_3_G
public static final int NETWORK_CLASS_4_G
public static final int SIM_STATE_UNKNOWN
public static final int SIM_STATE_ABSENT
public static final int SIM_STATE_PIN_REQUIRED
public static final int SIM_STATE_PUK_REQUIRED
public static final int SIM_STATE_NETWORK_LOCKED
public static final int SIM_STATE_READY
public static final int CALL_STATE_IDLE
public static final int CALL_STATE_RINGING
public static final int CALL_STATE_OFFHOOK
public static final int DATA_ACTIVITY_NONE
public static final int DATA_ACTIVITY_IN
public static final int DATA_ACTIVITY_OUT
public static final int DATA_ACTIVITY_INOUT
public static final int DATA_ACTIVITY_DORMANT
public static final int DATA_UNKNOWN
public static final int DATA_DISCONNECTED
public static final int DATA_CONNECTING
public static final int DATA_CONNECTED
public static final int DATA_SUSPENDED
public TelephonyManager(Context context)
public static TelephonyManager getDefault()
public static TelephonyManager from(Context context)
public String getDeviceSoftwareVersion()
Requires Permission:
READ_PHONE_STATE
public String getDeviceId()
Requires Permission:
READ_PHONE_STATE
public CellLocation getCellLocation()
Requires Permission:
ACCESS_COARSE_LOCATION
or
ACCESS_FINE_LOCATION
.
public void enableLocationUpdates()
PhoneStateListener.onCellLocationChanged
will be called on location updates.
Requires Permission: CONTROL_LOCATION_UPDATES
public void disableLocationUpdates()
PhoneStateListener.onCellLocationChanged
will be called on location updates.
Requires Permission: CONTROL_LOCATION_UPDATES
public List<NeighboringCellInfo> getNeighboringCellInfo()
Requires Permission: (@link android.Manifest.permission#ACCESS_COARSE_UPDATES}
public int getCurrentPhoneType()
PHONE_TYPE_NONE
,
PHONE_TYPE_GSM
,
PHONE_TYPE_CDMA
,
{@hide}
public int getPhoneType()
PHONE_TYPE_NONE
,
PHONE_TYPE_GSM
,
PHONE_TYPE_CDMA
,
PHONE_TYPE_SIP
public static int getPhoneType(int networkMode)
network
- modepublic static int getLteOnCdmaModeStatic()
PhoneConstants.LTE_ON_CDMA_UNKNOWN
, PhoneConstants.LTE_ON_CDMA_FALSE
or PhoneConstants.LTE_ON_CDMA_TRUE
public String getNetworkOperatorName()
Availability: Only when user is registered to a network. Result may be
unreliable on CDMA networks (use getPhoneType()
to determine if
on a CDMA network).
public String getNetworkOperator()
Availability: Only when user is registered to a network. Result may be
unreliable on CDMA networks (use getPhoneType()
to determine if
on a CDMA network).
public boolean isNetworkRoaming()
Availability: Only when user registered to a network.
public String getNetworkCountryIso()
Availability: Only when user is registered to a network. Result may be
unreliable on CDMA networks (use getPhoneType()
to determine if
on a CDMA network).
public int getNetworkType()
NETWORK_TYPE_UNKNOWN
,
NETWORK_TYPE_GPRS
,
NETWORK_TYPE_EDGE
,
NETWORK_TYPE_UMTS
,
NETWORK_TYPE_HSDPA
,
NETWORK_TYPE_HSUPA
,
NETWORK_TYPE_HSPA
,
NETWORK_TYPE_CDMA
,
NETWORK_TYPE_EVDO_0
,
NETWORK_TYPE_EVDO_A
,
NETWORK_TYPE_EVDO_B
,
NETWORK_TYPE_1xRTT
,
NETWORK_TYPE_IDEN
,
NETWORK_TYPE_LTE
,
NETWORK_TYPE_EHRPD
,
NETWORK_TYPE_HSPAP
public static int getNetworkClass(int networkType)
public String getNetworkTypeName()
public static String getNetworkTypeName(int type)
public boolean hasIccCard()
public int getSimState()
public String getSimOperator()
Availability: SIM state must be SIM_STATE_READY
getSimState()
public String getSimOperatorName()
Availability: SIM state must be SIM_STATE_READY
getSimState()
public String getSimCountryIso()
public String getSimSerialNumber()
Requires Permission:
READ_PHONE_STATE
public int getLteOnCdmaMode()
Phone#LTE_ON_CDMA_UNKNOWN
, Phone#LTE_ON_CDMA_FALSE
or Phone#LTE_ON_CDMA_TRUE
public String getSubscriberId()
Requires Permission:
READ_PHONE_STATE
public String getLine1Number()
Requires Permission:
READ_PHONE_STATE
public String getLine1AlphaTag()
Requires Permission:
READ_PHONE_STATE
public String getMsisdn()
Requires Permission:
READ_PHONE_STATE
public String getVoiceMailNumber()
Requires Permission:
READ_PHONE_STATE
public String getCompleteVoiceMailNumber()
Requires Permission:
CALL_PRIVILEGED
public int getVoiceMessageCount()
Requires Permission:
READ_PHONE_STATE
public String getVoiceMailAlphaTag()
Requires Permission:
READ_PHONE_STATE
public String getIsimImpi()
public String getIsimDomain()
public String[] getIsimImpu()
public int getCallState()
public int getDataActivity()
public int getDataState()
DATA_DISCONNECTED
,
DATA_CONNECTING
,
DATA_CONNECTED
,
DATA_SUSPENDED
public void listen(PhoneStateListener listener, int events)
To register a listener, pass a PhoneStateListener
and specify at least one telephony state of interest in
the events argument.
At registration, and when a specified telephony state
changes, the telephony manager invokes the appropriate
callback method on the listener object and passes the
current (udpated) values.
To unregister a listener, pass the listener object and set the
events argument to
LISTEN_NONE
(0).
listener
- The PhoneStateListener
object to register
(or unregister)events
- The telephony state(s) of interest to the listener,
as a bitwise-OR combination of PhoneStateListener
LISTEN_ flags.public int getCdmaEriIconIndex()
public int getCdmaEriIconMode()
public String getCdmaEriText()
public boolean isVoiceCapable()
"Voice capable" means that this device supports circuit-switched (i.e. voice) phone calls over the telephony network, and is allowed to display the in-call UI while a cellular voice call is active. This will be false on "data only" devices which can't make voice calls and don't support any in-call UI.
Note: the meaning of this flag is subtly different from the PackageManager.FEATURE_TELEPHONY system feature, which is available on any device with a telephony radio, even if the device is data-only.
public boolean isSmsCapable()
If true, this means that the device supports both sending and receiving sms via the telephony network.
Note: Voicemail waiting sms, cell broadcasting sms, and MMS are disabled when device doesn't support sms.