TelephonyManager.Listen(PhoneStateListener, PhoneStateListenerFlags) Method

Definition

Registers a listener object to receive notification of changes in specified telephony states.

[Android.Runtime.Register("listen", "(Landroid/telephony/PhoneStateListener;I)V", "GetListen_Landroid_telephony_PhoneStateListener_IHandler")]
public virtual void Listen (Android.Telephony.PhoneStateListener? listener, Android.Telephony.PhoneStateListenerFlags events);
[<Android.Runtime.Register("listen", "(Landroid/telephony/PhoneStateListener;I)V", "GetListen_Landroid_telephony_PhoneStateListener_IHandler")>]
abstract member Listen : Android.Telephony.PhoneStateListener * Android.Telephony.PhoneStateListenerFlags -> unit
override this.Listen : Android.Telephony.PhoneStateListener * Android.Telephony.PhoneStateListenerFlags -> unit

Parameters

listener
PhoneStateListener

The PhoneStateListener object to register (or unregister)

events
PhoneStateListenerFlags

The telephony state(s) of interest to the listener, as a bitwise-OR combination of PhoneStateListener LISTEN_ flags.

Attributes

Remarks

Registers a listener object to receive notification of changes in specified telephony states.

To register a listener, pass a PhoneStateListener and specify at least one telephony state of interest in the events argument.

At registration, and when a specified telephony state changes, the telephony manager invokes the appropriate callback method on the listener object and passes the current (updated) values.

To un-register a listener, pass the listener object and set the events argument to PhoneStateListener#LISTEN_NONE LISTEN_NONE (0).

If this TelephonyManager object has been created with #createForSubscriptionId, applies to the given subId. Otherwise, applies to SubscriptionManager#getDefaultSubscriptionId(). To listen events for multiple subIds, pass a separate listener object to each TelephonyManager object created with #createForSubscriptionId.

Note: if you call this method while in the middle of a binder transaction, you <b>must</b> call android.os.Binder#clearCallingIdentity() before calling this method. A SecurityException will be thrown otherwise.

This API should be used sparingly -- large numbers of listeners will cause system instability. If a process has registered too many listeners without unregistering them, it may encounter an IllegalStateException when trying to register more listeners.

This member is deprecated. Use #registerTelephonyCallback(Executor, TelephonyCallback).

Java documentation for android.telephony.TelephonyManager.listen(android.telephony.PhoneStateListener, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to