English | Site Directory

Android - An Open Handset Alliance Project

android.telephony
public final class

android.telephony.PhoneStateIntentReceiver

java.lang.Object
android.content.IntentReceiver
android.telephony.PhoneStateIntentReceiver

A IntentReceiver implementation that provides phone state and operation information.

There are five Intents you can register and listen for: the service state, phone call state, signal strength, message waiting indicator, and call forwarding indicator. For each of these intents you have to register with corresponding notify function before calling corresponding get function to access values. You can use unregisterIntent and registerIntent to stop and resume listening.

Summary

Constants

      Value  
String  INTENT_KEY_ASU    "asu" 
String  INTENT_KEY_CFI    "cfi" 
String  INTENT_KEY_MWI    "mwi" 

Public Constructors

          PhoneStateIntentReceiver()
default constructor
          PhoneStateIntentReceiver(Context context, Handler target)
Commonly use constructor

Public Methods

        boolean  getCallForwardingIndicator()
Return current call forwarding indicator state.
        boolean  getMessageWaitingIndicator()
Return current message waiting indicator state.
        boolean  getNotifyCallForwardingIndicator()
Check if registere for call forwarding notification
        boolean  getNotifyMessageWaitingIndicator()
Check if registere for message waiting notification
        boolean  getNotifyPhoneCallState()
Check if registere for phone call state notification
        boolean  getNotifyServiceState()
Check if registere for service state notification
        boolean  getNotifySignalStrength()
Check if registere for signal strength notification
        State  getPhoneState()
Returns current phone state
        ServiceState  getServiceState()
Returns current service state
        int  getSignalStrength()
Returns current signal strength in "asu", ranging from 0-31 or -1 if unknown For GSM, dBm = -113 + 2*asu 0 means "-113 dBm or less" 31 means "-51 dBm or greater"
        int  getSignalStrengthDbm()
Return current signal strength in "dBm", ranging from -113 - -51dBm or -1 if unknown
        void  notifyCallForwardingIndicator(int eventWhat)
Call this if you want to be notified of call forwarding states.
        void  notifyMessageWaitingIndicator(int eventWhat)
Call this if you want to be notified of message waiting states.
        void  notifyPhoneCallState(int eventWhat)
Call this if you want to be notified of phone call states.
        void  notifyServiceState(int eventWhat)
Call this if you want to be notified of phone service states.
        void  notifySignalStrength(int eventWhat)
Call this if you want to be notified of radio signal strength.
        void  onReceiveIntent(Context context, Intent intent)
This method is called when the IntentReceiver is receiving an Intent broadcast.
        void  registerIntent()
Register to be run in caller thread with intent filter
        void  setContext(Context c)
Set the application environment of caller
        void  setTarget(Handler h)
Set the message post and callback handler provided by caller
        void  unregisterIntent()
Unregister from caller thread
Methods inherited from class android.content.IntentReceiver
Methods inherited from class java.lang.Object

Details

Constants

public static final String INTENT_KEY_ASU

Constant Value: "asu"

public static final String INTENT_KEY_CFI

Constant Value: "cfi"

public static final String INTENT_KEY_MWI

Constant Value: "mwi"

Public Constructors

public PhoneStateIntentReceiver()

default constructor

public PhoneStateIntentReceiver(Context context, Handler target)

Commonly use constructor

Parameters

context the application environment of caller
target the message post and callback handler provided by caller

Public Methods

public boolean getCallForwardingIndicator()

Return current call forwarding indicator state.

Returns

  • true if there are call forwarding. Throws RuntimeException if client has not called notifyCallForwardingIndicator()

public boolean getMessageWaitingIndicator()

Return current message waiting indicator state.

Returns

  • true if there are messages waiting. Throws RuntimeException if client has not called notifyMessageWaitingIndicator()

public boolean getNotifyCallForwardingIndicator()

Check if registere for call forwarding notification

Returns

  • true for registered

public boolean getNotifyMessageWaitingIndicator()

Check if registere for message waiting notification

Returns

  • true for registered

public boolean getNotifyPhoneCallState()

Check if registere for phone call state notification

Returns

  • true for registered

public boolean getNotifyServiceState()

Check if registere for service state notification

Returns

  • true for registered

public boolean getNotifySignalStrength()

Check if registere for signal strength notification

Returns

  • true for registered

public State getPhoneState()

Returns current phone state

Returns

  • Phone.State enum. Phone.IDLE if not yet updated. Throws RuntimeException if client has not called notifyPhoneCallState()

public ServiceState getServiceState()

Returns current service state

Returns

  • ServiceState object, "out of service" info if not yet updated. Throws RuntimeException if client has not called notifyServiceState()

public int getSignalStrength()

Returns current signal strength in "asu", ranging from 0-31 or -1 if unknown For GSM, dBm = -113 + 2*asu 0 means "-113 dBm or less" 31 means "-51 dBm or greater"

Returns

  • signal strength in asu, -1 if not yet updated Throws RuntimeException if client has not called notifySignalStrength()

public int getSignalStrengthDbm()

Return current signal strength in "dBm", ranging from -113 - -51dBm or -1 if unknown

Returns

  • signal strength in dBm, -1 if not yet updated Throws RuntimeException if client has not called notifySignalStrength()

public void notifyCallForwardingIndicator(int eventWhat)

Call this if you want to be notified of call forwarding states.

Parameters

eventWhat the callback event what code.

public void notifyMessageWaitingIndicator(int eventWhat)

Call this if you want to be notified of message waiting states.

Parameters

eventWhat the callback event what code.

public void notifyPhoneCallState(int eventWhat)

Call this if you want to be notified of phone call states.

Parameters

eventWhat the callback event what code.

public void notifyServiceState(int eventWhat)

Call this if you want to be notified of phone service states.

Parameters

eventWhat the callback event what code.

public void notifySignalStrength(int eventWhat)

Call this if you want to be notified of radio signal strength.

Parameters

eventWhat the callback event what code.

public void onReceiveIntent(Context context, Intent intent)

This method is called when the IntentReceiver is receiving an Intent broadcast. During this time you can use the other methods on IntentReceiver to view/modify the current result values. The function is normally called from the main thread of its process, so you should never perform long-running operations in it (there is a timeout of 10 seconds that the system allows before considering the receiver to be blocked and a candidate to be killed). You cannot launch a popup dialog in your implementation of onReceiveIntent().

If this IntentReceiver was launched through a <receiver> tag, then the object is no longer alive after returning from this function. This means you should not perform any operations that return a result to you asynchronously -- in particular, for interacting with services, you should use startService(Intent, Bundle) instead of bindService(Intent, ServiceConnection, int).

Parameters

context The Context in which the receiver is running.
intent The Intent being received.

public void registerIntent()

Register to be run in caller thread with intent filter

public void setContext(Context c)

Set the application environment of caller

Parameters

c the application environment of caller

public void setTarget(Handler h)

Set the message post and callback handler provided by caller

Parameters

h the message post and callback handler provided by caller

public void unregisterIntent()

Unregister from caller thread
Build m5-rc15i - 10 Jun 2008 13:54