PhoneStateListener
public
class
PhoneStateListener
extends Object
java.lang.Object | |
↳ | android.telephony.PhoneStateListener |
A listener class for monitoring changes in specific telephony states on the device, including service state, signal strength, message waiting indicator (voicemail), and others.
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.
Summary
Constants | |
---|---|
int |
LISTEN_CALL_FORWARDING_INDICATOR
Listen for changes to the call-forwarding indicator. |
int |
LISTEN_CALL_STATE
Listen for changes to the device call state. |
int |
LISTEN_CELL_INFO
Listen for changes to observed cell info. |
int |
LISTEN_CELL_LOCATION
Listen for changes to the device's cell location. Note that this will result in frequent callbacks to the listener. |
int |
LISTEN_DATA_ACTIVITY
Listen for changes to the direction of data traffic on the data connection (cellular). |
int |
LISTEN_DATA_CONNECTION_STATE
Listen for changes to the data connection state (cellular). |
int |
LISTEN_MESSAGE_WAITING_INDICATOR
Listen for changes to the message-waiting indicator. |
int |
LISTEN_NONE
Stop listening for updates. |
int |
LISTEN_SERVICE_STATE
Listen for changes to the network service state (cellular). |
int |
LISTEN_SIGNAL_STRENGTH
This constant was deprecated
in API level 7.
by |
int |
LISTEN_SIGNAL_STRENGTHS
Listen for changes to the network signal strengths (cellular). |
int |
LISTEN_USER_MOBILE_DATA_STATE
Listen for changes to the user mobile data state |
Public constructors | |
---|---|
PhoneStateListener()
Create a PhoneStateListener for the Phone with the default subscription. |
Public methods | |
---|---|
void
|
onCallForwardingIndicatorChanged(boolean cfi)
Callback invoked when the call-forwarding indicator changes. |
void
|
onCallStateChanged(int state, String phoneNumber)
Callback invoked when device call state changes. |
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
|
onDataConnectionStateChanged(int state, int networkType)
same as above, but with the network type. |
void
|
onDataConnectionStateChanged(int state)
Callback invoked when connection state changes. |
void
|
onMessageWaitingIndicatorChanged(boolean mwi)
Callback invoked when the message-waiting indicator changes. |
void
|
onServiceStateChanged(ServiceState serviceState)
Callback invoked when device service state changes. |
void
|
onSignalStrengthChanged(int asu)
This method was deprecated
in API level 5.
Use |
void
|
onSignalStrengthsChanged(SignalStrength signalStrength)
Callback invoked when network signal strengths changes. |
void
|
onUserMobileDataStateChanged(boolean enabled)
Callback invoked when the user mobile data state has changed |
Inherited methods | |
---|---|
Constants
LISTEN_CALL_FORWARDING_INDICATOR
int LISTEN_CALL_FORWARDING_INDICATOR
Listen for changes to the call-forwarding indicator.
Requires Permission: READ_PHONE_STATE
Constant Value: 8 (0x00000008)
LISTEN_CALL_STATE
int LISTEN_CALL_STATE
Listen for changes to the device call state.
See also:
Constant Value: 32 (0x00000020)
LISTEN_CELL_INFO
int LISTEN_CELL_INFO
Listen for changes to observed cell info.
See also:
Constant Value: 1024 (0x00000400)
LISTEN_CELL_LOCATION
int LISTEN_CELL_LOCATION
Listen for changes to the device's cell location. Note that this will result in frequent callbacks to the listener.
Requires Permission: 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.
See also:
Constant Value: 16 (0x00000010)
LISTEN_DATA_ACTIVITY
int LISTEN_DATA_ACTIVITY
Listen for changes to the direction of data traffic on the data connection (cellular).
Example: The status bar uses this to display the appropriate data-traffic icon.
See also:
Constant Value: 128 (0x00000080)
LISTEN_DATA_CONNECTION_STATE
int LISTEN_DATA_CONNECTION_STATE
Listen for changes to the data connection state (cellular).
See also:
Constant Value: 64 (0x00000040)
LISTEN_MESSAGE_WAITING_INDICATOR
int LISTEN_MESSAGE_WAITING_INDICATOR
Listen for changes to the message-waiting indicator.
Requires Permission: READ_PHONE_STATE
Example: The status bar uses this to determine when to display the voicemail icon.
Constant Value: 4 (0x00000004)
LISTEN_NONE
int LISTEN_NONE
Stop listening for updates.
Constant Value: 0 (0x00000000)
LISTEN_SERVICE_STATE
int LISTEN_SERVICE_STATE
Listen for changes to the network service state (cellular).
Constant Value: 1 (0x00000001)
LISTEN_SIGNAL_STRENGTH
int LISTEN_SIGNAL_STRENGTH
This constant was deprecated
in API level 7.
by LISTEN_SIGNAL_STRENGTHS
Listen for changes to the network signal strength (cellular).
Requires Permission: READ_PHONE_STATE
See also:
Constant Value: 2 (0x00000002)
LISTEN_SIGNAL_STRENGTHS
int LISTEN_SIGNAL_STRENGTHS
Listen for changes to the network signal strengths (cellular).
Example: The status bar uses this to control the signal-strength icon.
See also:
Constant Value: 256 (0x00000100)
LISTEN_USER_MOBILE_DATA_STATE
int LISTEN_USER_MOBILE_DATA_STATE
Listen for changes to the user mobile data state
See also:
Constant Value: 524288 (0x00080000)
Public constructors
PhoneStateListener
PhoneStateListener ()
Create a PhoneStateListener for the Phone with the default subscription. This class requires Looper.myLooper() not return null.
Public methods
onCallForwardingIndicatorChanged
void onCallForwardingIndicatorChanged (boolean cfi)
Callback invoked when the call-forwarding indicator changes.
Parameters | |
---|---|
cfi |
boolean |
onCallStateChanged
void onCallStateChanged (int state, String phoneNumber)
Callback invoked when device call state changes.
Parameters | |
---|---|
state |
int : call state |
phoneNumber |
String : call phone number. If application does not have
READ_PHONE_STATE permission, an empty
string will be passed as an argument. |
onCellInfoChanged
void onCellInfoChanged (List<CellInfo> cellInfo)
Callback invoked when a observed cell info has changed, or new cells have been added or removed.
Parameters | |
---|---|
cellInfo |
List : is the list of currently visible cells.
|
onCellLocationChanged
void onCellLocationChanged (CellLocation location)
Callback invoked when device cell location changes.
Parameters | |
---|---|
location |
CellLocation |
onDataActivity
void onDataActivity (int direction)
Callback invoked when data activity state changes.
Parameters | |
---|---|
direction |
int |
onDataConnectionStateChanged
void onDataConnectionStateChanged (int state, int networkType)
same as above, but with the network type. Both called.
Parameters | |
---|---|
state |
int |
networkType |
int |
onDataConnectionStateChanged
void onDataConnectionStateChanged (int state)
Callback invoked when connection state changes.
Parameters | |
---|---|
state |
int |
onMessageWaitingIndicatorChanged
void onMessageWaitingIndicatorChanged (boolean mwi)
Callback invoked when the message-waiting indicator changes.
Parameters | |
---|---|
mwi |
boolean |
onServiceStateChanged
void onServiceStateChanged (ServiceState serviceState)
Callback invoked when device service state changes.
Parameters | |
---|---|
serviceState |
ServiceState |
onSignalStrengthChanged
void onSignalStrengthChanged (int asu)
This method was deprecated
in API level 5.
Use onSignalStrengthsChanged(SignalStrength)
Callback invoked when network signal strength changes.
Parameters | |
---|---|
asu |
int |
onSignalStrengthsChanged
void onSignalStrengthsChanged (SignalStrength signalStrength)
Callback invoked when network signal strengths changes.
Parameters | |
---|---|
signalStrength |
SignalStrength |
onUserMobileDataStateChanged
void onUserMobileDataStateChanged (boolean enabled)
Callback invoked when the user mobile data state has changed
Parameters | |
---|---|
enabled |
boolean : indicates whether the current user mobile data state is enabled or disabled.
|
Classes
- AccessNetworkConstants
- AccessNetworkConstants.AccessNetworkType
- AccessNetworkConstants.EutranBand
- AccessNetworkConstants.GeranBand
- AccessNetworkConstants.UtranBand
- CarrierConfigManager
- CellIdentity
- CellIdentityCdma
- CellIdentityGsm
- CellIdentityLte
- CellIdentityTdscdma
- CellIdentityWcdma
- CellInfo
- CellInfoCdma
- CellInfoGsm
- CellInfoLte
- CellInfoWcdma
- CellLocation
- CellSignalStrength
- CellSignalStrengthCdma
- CellSignalStrengthGsm
- CellSignalStrengthLte
- CellSignalStrengthWcdma
- IccOpenLogicalChannelResponse
- MbmsDownloadSession
- MbmsStreamingSession
- NeighboringCellInfo
- NetworkScan
- NetworkScanRequest
- PhoneNumberFormattingTextWatcher
- PhoneNumberUtils
- PhoneStateListener
- RadioAccessSpecifier
- ServiceState
- SignalStrength
- SmsManager
- SmsMessage
- SmsMessage.SubmitPdu
- SubscriptionInfo
- SubscriptionManager
- SubscriptionManager.OnSubscriptionsChangedListener
- SubscriptionPlan
- SubscriptionPlan.Builder
- TelephonyManager
- TelephonyManager.UssdResponseCallback
- TelephonyScanManager
- TelephonyScanManager.NetworkScanCallback
- VisualVoicemailService
- VisualVoicemailService.VisualVoicemailTask
- VisualVoicemailSms
- VisualVoicemailSmsFilterSettings
- VisualVoicemailSmsFilterSettings.Builder
Enums