FileDocCategorySizeDatePackage
PhoneStateListener.javaAPI DocAndroid 1.5 API9382Wed May 06 22:42:00 BST 2009android.telephony

PhoneStateListener

public class PhoneStateListener extends Object
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 {@link TelephonyManager#listen 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.

Fields Summary
public static final int
LISTEN_NONE
Stop listening for updates.
public static final int
LISTEN_SERVICE_STATE
Listen for changes to the network service state (cellular).
public static final int
LISTEN_SIGNAL_STRENGTH
Listen for changes to the network signal strength (cellular).

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

public static final int
LISTEN_MESSAGE_WAITING_INDICATOR
Listen for changes to the message-waiting indicator.

Example: The status bar uses this to determine when to display the voicemail icon.

public static final int
LISTEN_CALL_FORWARDING_INDICATOR
Listen for changes to the call-forwarding indicator.
public static final int
LISTEN_CELL_LOCATION
Listen for changes to the device's cell location. Note that this will result in frequent callbacks to the listener. {@more} Requires Permission: {@link android.Manifest.permission#ACCESS_COARSE_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 {@link android.location.LocationManager location manager} instead.

public static final int
LISTEN_CALL_STATE
Listen for changes to the device call state.
public static final int
LISTEN_DATA_CONNECTION_STATE
Listen for changes to the data connection state (cellular).
public static final 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.
com.android.internal.telephony.IPhoneStateListener
callback
The callback methods need to be called on the handler thread where this object was created. If the binder did that for us it'd be nice.
android.os.Handler
mHandler
Constructors Summary
public PhoneStateListener()


      
    
Methods Summary
public voidonCallForwardingIndicatorChanged(boolean cfi)
Callback invoked when the call-forwarding indicator changes.

        // default implementation empty
    
public voidonCallStateChanged(int state, java.lang.String incomingNumber)
Callback invoked when device call state changes.

see
TelephonyManager#CALL_STATE_IDLE
see
TelephonyManager#CALL_STATE_RINGING
see
TelephonyManager#CALL_STATE_OFFHOOK

        // default implementation empty
    
public voidonCellLocationChanged(android.telephony.CellLocation location)
Callback invoked when device cell location changes.

        // default implementation empty
    
public voidonDataActivity(int direction)
Callback invoked when data activity state changes.

see
TelephonyManager#DATA_ACTIVITY_NONE
see
TelephonyManager#DATA_ACTIVITY_IN
see
TelephonyManager#DATA_ACTIVITY_OUT
see
TelephonyManager#DATA_ACTIVITY_INOUT

        // default implementation empty
    
public voidonDataConnectionStateChanged(int state)
Callback invoked when connection state changes.

see
TelephonyManager#DATA_DISCONNECTED
see
TelephonyManager#DATA_CONNECTING
see
TelephonyManager#DATA_CONNECTED
see
TelephonyManager#DATA_SUSPENDED

        // default implementation empty
    
public voidonMessageWaitingIndicatorChanged(boolean mwi)
Callback invoked when the message-waiting indicator changes.

        // default implementation empty
    
public voidonServiceStateChanged(android.telephony.ServiceState serviceState)
Callback invoked when device service state changes.

see
ServiceState#STATE_EMERGENCY_ONLY
see
ServiceState#STATE_IN_SERVICE
see
ServiceState#STATE_OUT_OF_SERVICE
see
ServiceState#STATE_POWER_OFF

        // default implementation empty
    
public voidonSignalStrengthChanged(int asu)
Callback invoked when network signal strength changes.

see
ServiceState#STATE_EMERGENCY_ONLY
see
ServiceState#STATE_IN_SERVICE
see
ServiceState#STATE_OUT_OF_SERVICE
see
ServiceState#STATE_POWER_OFF

        // default implementation empty