public class

PhoneStateListener

extends Object
java.lang.Object
   ↳ android.telephony.PhoneStateListener

Class Overview

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_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 is deprecated. by LISTEN_SIGNAL_STRENGTHS
int LISTEN_SIGNAL_STRENGTHS Listen for changes to the network signal strengths (cellular).
Public Constructors
PhoneStateListener()
Public Methods
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 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)
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 onServiceStateChanged(ServiceState serviceState)
Callback invoked when device service state changes.
void onSignalStrengthChanged(int asu)
This method is deprecated. Use onSignalStrengthsChanged(SignalStrength)
void onSignalStrengthsChanged(SignalStrength signalStrength)
Callback invoked when network signal strengths changes.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int LISTEN_CALL_FORWARDING_INDICATOR

Since: API Level 1

Listen for changes to the call-forwarding indicator.

Requires Permission: READ_PHONE_STATE

Constant Value: 8 (0x00000008)

public static final int LISTEN_CALL_STATE

Since: API Level 1

Listen for changes to the device call state.

Requires Permission: READ_PHONE_STATE

Constant Value: 32 (0x00000020)

public static final int LISTEN_CELL_LOCATION

Since: API Level 1

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.

Constant Value: 16 (0x00000010)

public static final int LISTEN_DATA_ACTIVITY

Since: API Level 1

Listen for changes to the direction of data traffic on the data connection (cellular).

Requires Permission: READ_PHONE_STATE Example: The status bar uses this to display the appropriate data-traffic icon.

Constant Value: 128 (0x00000080)

public static final int LISTEN_DATA_CONNECTION_STATE

Since: API Level 1

Listen for changes to the data connection state (cellular).

Constant Value: 64 (0x00000040)

public static final int LISTEN_MESSAGE_WAITING_INDICATOR

Since: API Level 1

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)

public static final int LISTEN_NONE

Since: API Level 1

Stop listening for updates.

Constant Value: 0 (0x00000000)

public static final int LISTEN_SERVICE_STATE

Since: API Level 1

Listen for changes to the network service state (cellular).

Constant Value: 1 (0x00000001)

public static final int LISTEN_SIGNAL_STRENGTH

Since: API Level 1

This constant is deprecated.
by LISTEN_SIGNAL_STRENGTHS

Listen for changes to the network signal strength (cellular).

Requires Permission: READ_PHONE_STATE

Constant Value: 2 (0x00000002)

public static final int LISTEN_SIGNAL_STRENGTHS

Since: API Level 7

Listen for changes to the network signal strengths (cellular).

Example: The status bar uses this to control the signal-strength icon.

Constant Value: 256 (0x00000100)

Public Constructors

public PhoneStateListener ()

Since: API Level 1

Public Methods

public void onCallForwardingIndicatorChanged (boolean cfi)

Since: API Level 1

Callback invoked when the call-forwarding indicator changes.

public void onCallStateChanged (int state, String incomingNumber)

Since: API Level 1

Callback invoked when device call state changes.

public void onCellLocationChanged (CellLocation location)

Since: API Level 1

Callback invoked when device cell location changes.

public void onDataActivity (int direction)

Since: API Level 1

Callback invoked when data activity state changes.

public void onDataConnectionStateChanged (int state)

Since: API Level 1

Callback invoked when connection state changes.

public void onDataConnectionStateChanged (int state, int networkType)

Since: API Level 7

same as above, but with the network type. Both called.

public void onMessageWaitingIndicatorChanged (boolean mwi)

Since: API Level 1

Callback invoked when the message-waiting indicator changes.

public void onServiceStateChanged (ServiceState serviceState)

Since: API Level 1

Callback invoked when device service state changes.

public void onSignalStrengthChanged (int asu)

Since: API Level 1

This method is deprecated.
Use onSignalStrengthsChanged(SignalStrength)

Callback invoked when network signal strength changes.

public void onSignalStrengthsChanged (SignalStrength signalStrength)

Since: API Level 7

Callback invoked when network signal strengths changes.