public class PhoneStateListener extends Object
Override the methods for the state that you wish to receive updates for, and
pass your PhoneStateListener object, along with bitwise-or of the LISTEN_
flags to TelephonyManager.listen()
.
Note that access to some telephony information is permission-protected. Your application won't receive updates for protected information unless it has the appropriate permissions declared in its manifest file. Where permissions apply, they are noted in the appropriate LISTEN_ flags.
Modifier and Type | Field and Description |
---|---|
static int |
LISTEN_CALL_FORWARDING_INDICATOR
Listen for changes to the call-forwarding indicator.
|
static int |
LISTEN_CALL_STATE
Listen for changes to the device call state.
|
static int |
LISTEN_CARRIER_NETWORK_CHANGE
Listen for carrier network changes indicated by a carrier app.
|
static int |
LISTEN_CELL_INFO
Listen for changes to observed cell info.
|
static int |
LISTEN_CELL_LOCATION
Listen for changes to the device's cell location.
|
static int |
LISTEN_DATA_ACTIVITY
Listen for changes to the direction of data traffic on the data
connection (cellular).
|
static int |
LISTEN_DATA_CONNECTION_REAL_TIME_INFO
Deprecated.
Use
TelephonyManager#getModemActivityInfo() |
static int |
LISTEN_DATA_CONNECTION_STATE
Listen for changes to the data connection state (cellular).
|
static int |
LISTEN_MESSAGE_WAITING_INDICATOR
Listen for changes to the message-waiting indicator.
|
static int |
LISTEN_NONE
Stop listening for updates.
|
static int |
LISTEN_OEM_HOOK_RAW_EVENT
Listen for OEM hook raw event
|
static int |
LISTEN_OTASP_CHANGED
Listen for changes to OTASP mode.
|
static int |
LISTEN_PRECISE_CALL_STATE
Listen for precise changes and fails to the device calls (cellular).
|
static int |
LISTEN_PRECISE_DATA_CONNECTION_STATE
Listen for precise changes and fails on the data connection (cellular).
|
static int |
LISTEN_SERVICE_STATE
Listen for changes to the network service state (cellular).
|
static int |
LISTEN_SIGNAL_STRENGTH
Deprecated.
|
static int |
LISTEN_SIGNAL_STRENGTHS
Listen for changes to the network signal strengths (cellular).
|
static int |
LISTEN_VOLTE_STATE
Listen for changes to LTE network state
|
protected int |
mSubId |
Constructor and Description |
---|
PhoneStateListener()
Create a PhoneStateListener for the Phone with the default subscription.
|
PhoneStateListener(int subId)
Create a PhoneStateListener for the Phone using the specified subscription.
|
PhoneStateListener(int subId,
Looper looper)
Create a PhoneStateListener for the Phone using the specified subscription
and non-null Looper.
|
PhoneStateListener(Looper looper)
Create a PhoneStateListener for the Phone with the default subscription
using a particular non-null Looper.
|
Modifier and Type | Method and Description |
---|---|
void |
onCallForwardingIndicatorChanged(boolean cfi)
Callback invoked when the call-forwarding indicator changes.
|
void |
onCallStateChanged(int state,
String incomingNumber)
Callback invoked when device call state changes.
|
void |
onCarrierNetworkChange(boolean active)
Callback invoked when telephony has received notice from a carrier
app that a network action that could result in connectivity loss
has been requested by an app using
android.telephony.TelephonyManager#notifyCarrierNetworkChange(boolean) |
void |
onCellInfoChanged(List<CellInfo> cellInfo)
Callback invoked when a observed cell info has changed,
or new cells have been added or removed.
|
void |
onCellLocationChanged(CellLocation location)
Callback invoked when device cell location changes.
|
void |
onDataActivity(int direction)
Callback invoked when data activity state changes.
|
void |
onDataConnectionRealTimeInfoChanged(DataConnectionRealTimeInfo dcRtInfo)
Callback invoked when data connection state changes with precise information.
|
void |
onDataConnectionStateChanged(int state)
Callback invoked when connection state changes.
|
void |
onDataConnectionStateChanged(int state,
int networkType)
same as above, but with the network type.
|
void |
onMessageWaitingIndicatorChanged(boolean mwi)
Callback invoked when the message-waiting indicator changes.
|
void |
onOemHookRawEvent(byte[] rawData)
Callback invoked when OEM hook raw event is received.
|
void |
onOtaspChanged(int otaspMode)
The Over The Air Service Provisioning (OTASP) has changed.
|
void |
onPreciseCallStateChanged(PreciseCallState callState)
Callback invoked when precise device call state changes.
|
void |
onPreciseDataConnectionStateChanged(PreciseDataConnectionState dataConnectionState)
Callback invoked when data connection state changes with precise information.
|
void |
onServiceStateChanged(ServiceState serviceState)
Callback invoked when device service state changes.
|
void |
onSignalStrengthChanged(int asu)
Deprecated.
|
void |
onSignalStrengthsChanged(SignalStrength signalStrength)
Callback invoked when network signal strengths changes.
|
void |
onVoLteServiceStateChanged(VoLteServiceState stateInfo)
Callback invoked when the service state of LTE network
related to the VoLTE service has changed.
|
public static final int LISTEN_NONE
public static final int LISTEN_SERVICE_STATE
@Deprecated public static final int LISTEN_SIGNAL_STRENGTH
LISTEN_SIGNAL_STRENGTHS
READ_PHONE_STATE
public static final int LISTEN_MESSAGE_WAITING_INDICATOR
READ_PHONE_STATE
Example: The status bar uses this to determine when to display the voicemail icon.
public static final int LISTEN_CALL_FORWARDING_INDICATOR
READ_PHONE_STATE
public static final int LISTEN_CELL_LOCATION
ACCESS_COARSE_LOCATION
If you need regular location updates but want more control over
the update interval or location precision, you can set up a listener
through the location manager
instead.
public static final int LISTEN_CALL_STATE
public static final int LISTEN_DATA_CONNECTION_STATE
public static final int LISTEN_DATA_ACTIVITY
onDataActivity(int)
,
Constant Field Valuespublic static final int LISTEN_SIGNAL_STRENGTHS
Example: The status bar uses this to control the signal-strength icon.
public static final int LISTEN_OTASP_CHANGED
onOtaspChanged(int)
,
Constant Field Valuespublic static final int LISTEN_CELL_INFO
public static final int LISTEN_PRECISE_CALL_STATE
READ_PRECISE_PHONE_STATE
public static final int LISTEN_PRECISE_DATA_CONNECTION_STATE
READ_PRECISE_PHONE_STATE
@Deprecated public static final int LISTEN_DATA_CONNECTION_REAL_TIME_INFO
TelephonyManager#getModemActivityInfo()
READ_PRECISE_PHONE_STATE
public static final int LISTEN_VOLTE_STATE
#onLteNetworkStateChanged
,
Constant Field Valuespublic static final int LISTEN_OEM_HOOK_RAW_EVENT
onOemHookRawEvent(byte[])
,
Constant Field Valuespublic static final int LISTEN_CARRIER_NETWORK_CHANGE
#onCarrierNetworkRequest
,
TelephonyManager#notifyCarrierNetworkChange(boolean)
,
Constant Field Valuesprotected int mSubId
public PhoneStateListener()
public PhoneStateListener(Looper looper)
public PhoneStateListener(int subId)
public PhoneStateListener(int subId, Looper looper)
public void onServiceStateChanged(ServiceState serviceState)
@Deprecated public void onSignalStrengthChanged(int asu)
onSignalStrengthsChanged(SignalStrength)
public void onMessageWaitingIndicatorChanged(boolean mwi)
public void onCallForwardingIndicatorChanged(boolean cfi)
public void onCellLocationChanged(CellLocation location)
public void onCallStateChanged(int state, String incomingNumber)
state
- call stateincomingNumber
- incoming call phone number. If application does not have
READ_PHONE_STATE
permission, an empty
string will be passed as an argument.TelephonyManager.CALL_STATE_IDLE
,
TelephonyManager.CALL_STATE_RINGING
,
TelephonyManager.CALL_STATE_OFFHOOK
public void onDataConnectionStateChanged(int state)
public void onDataConnectionStateChanged(int state, int networkType)
public void onDataActivity(int direction)
public void onSignalStrengthsChanged(SignalStrength signalStrength)
public void onOtaspChanged(int otaspMode)
otaspMode
- is integer OTASP_UNKNOWN=1
means the value is currently unknown and the system should wait until
OTASP_NEEDED=2 or OTASP_NOT_NEEDED=3 is received before
making the decision to perform OTASP or not.
public void onCellInfoChanged(List<CellInfo> cellInfo)
cellInfo
- is the list of currently visible cells.public void onPreciseCallStateChanged(PreciseCallState callState)
public void onPreciseDataConnectionStateChanged(PreciseDataConnectionState dataConnectionState)
public void onDataConnectionRealTimeInfoChanged(DataConnectionRealTimeInfo dcRtInfo)
public void onVoLteServiceStateChanged(VoLteServiceState stateInfo)
stateInfo
- is the current LTE network informationpublic void onOemHookRawEvent(byte[] rawData)
rawData
- is the byte array of the OEM hook raw data.public void onCarrierNetworkChange(boolean active)
android.telephony.TelephonyManager#notifyCarrierNetworkChange(boolean)
active
- Whether the carrier network change is or shortly
will be active. This value is true to indicate
showing alternative UI and false to stop.