SensorManager.RegisterListener Method

Definition

Overloads

RegisterListener(ISensorEventListener, Sensor, SensorDelay, Int32, Handler)

Registers a android.hardware.SensorEventListener SensorEventListener for the given sensor at the given sampling frequency and the given maximum reporting latency.

RegisterListener(ISensorEventListener, Sensor, SensorDelay, Int32)

Registers a android.hardware.SensorEventListener SensorEventListener for the given sensor at the given sampling frequency and the given maximum reporting latency.

RegisterListener(ISensorEventListener, Sensor, SensorDelay, Handler)

Registers a android.hardware.SensorEventListener SensorEventListener for the given sensor.

RegisterListener(ISensorEventListener, Sensor, SensorDelay)

Registers a android.hardware.SensorEventListener SensorEventListener for the given sensor at the given sampling frequency.

RegisterListener(ISensorListener, Int32)
Obsolete.

Registers a listener for given sensors.

RegisterListener(ISensorListener, Int32, SensorDelay)
Obsolete.

Registers a SensorListener for given sensors.

RegisterListener(ISensorEventListener, Sensor, SensorDelay, Int32, Handler)

Registers a android.hardware.SensorEventListener SensorEventListener for the given sensor at the given sampling frequency and the given maximum reporting latency.

[Android.Runtime.Register("registerListener", "(Landroid/hardware/SensorEventListener;Landroid/hardware/Sensor;IILandroid/os/Handler;)Z", "GetRegisterListener_Landroid_hardware_SensorEventListener_Landroid_hardware_Sensor_IILandroid_os_Handler_Handler")]
public virtual bool RegisterListener (Android.Hardware.ISensorEventListener? listener, Android.Hardware.Sensor? sensor, Android.Hardware.SensorDelay samplingPeriodUs, int maxReportLatencyUs, Android.OS.Handler? handler);
[<Android.Runtime.Register("registerListener", "(Landroid/hardware/SensorEventListener;Landroid/hardware/Sensor;IILandroid/os/Handler;)Z", "GetRegisterListener_Landroid_hardware_SensorEventListener_Landroid_hardware_Sensor_IILandroid_os_Handler_Handler")>]
abstract member RegisterListener : Android.Hardware.ISensorEventListener * Android.Hardware.Sensor * Android.Hardware.SensorDelay * int * Android.OS.Handler -> bool
override this.RegisterListener : Android.Hardware.ISensorEventListener * Android.Hardware.Sensor * Android.Hardware.SensorDelay * int * Android.OS.Handler -> bool

Parameters

listener
ISensorEventListener

A android.hardware.SensorEventListener SensorEventListener object that will receive the sensor events. If the application is interested in receiving flush complete notifications, it should register with android.hardware.SensorEventListener SensorEventListener2 instead.

sensor
Sensor

The android.hardware.Sensor Sensor to register to.

samplingPeriodUs
SensorDelay

The desired delay between two consecutive events in microseconds. This is only a hint to the system. Events may be received faster or slower than the specified rate. Usually events are received faster. Can be one of #SENSOR_DELAY_NORMAL, #SENSOR_DELAY_UI, #SENSOR_DELAY_GAME, #SENSOR_DELAY_FASTEST or the delay in microseconds.

maxReportLatencyUs
Int32

Maximum time in microseconds that events can be delayed before being reported to the application. A large value allows reducing the power consumption associated with the sensor. If maxReportLatencyUs is set to zero, events are delivered as soon as they are available, which is equivalent to calling #registerListener(SensorEventListener, Sensor, int).

handler
Handler

The android.os.Handler Handler the android.hardware.SensorEvent sensor events will be delivered to.

Returns

true if the sensor is supported and successfully enabled.

Attributes

Remarks

Registers a android.hardware.SensorEventListener SensorEventListener for the given sensor at the given sampling frequency and the given maximum reporting latency.

Java documentation for android.hardware.SensorManager.registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int, int, android.os.Handler).

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.

See also

  • <xref:Android.Hardware.SensorManager.RegisterListener(Android.Hardware.ISensorEventListener%2c+Android.Hardware.Sensor%2c+Android.Hardware.Sensor%2c+Android.Hardware.Sensor)>

Applies to

RegisterListener(ISensorEventListener, Sensor, SensorDelay, Int32)

Registers a android.hardware.SensorEventListener SensorEventListener for the given sensor at the given sampling frequency and the given maximum reporting latency.

[Android.Runtime.Register("registerListener", "(Landroid/hardware/SensorEventListener;Landroid/hardware/Sensor;II)Z", "GetRegisterListener_Landroid_hardware_SensorEventListener_Landroid_hardware_Sensor_IIHandler")]
public virtual bool RegisterListener (Android.Hardware.ISensorEventListener? listener, Android.Hardware.Sensor? sensor, Android.Hardware.SensorDelay samplingPeriodUs, int maxReportLatencyUs);
[<Android.Runtime.Register("registerListener", "(Landroid/hardware/SensorEventListener;Landroid/hardware/Sensor;II)Z", "GetRegisterListener_Landroid_hardware_SensorEventListener_Landroid_hardware_Sensor_IIHandler")>]
abstract member RegisterListener : Android.Hardware.ISensorEventListener * Android.Hardware.Sensor * Android.Hardware.SensorDelay * int -> bool
override this.RegisterListener : Android.Hardware.ISensorEventListener * Android.Hardware.Sensor * Android.Hardware.SensorDelay * int -> bool

Parameters

listener
ISensorEventListener

A android.hardware.SensorEventListener SensorEventListener object that will receive the sensor events. If the application is interested in receiving flush complete notifications, it should register with android.hardware.SensorEventListener SensorEventListener2 instead.

sensor
Sensor

The android.hardware.Sensor Sensor to register to.

samplingPeriodUs
SensorDelay

The desired delay between two consecutive events in microseconds. This is only a hint to the system. Events may be received faster or slower than the specified rate. Usually events are received faster. Can be one of #SENSOR_DELAY_NORMAL, #SENSOR_DELAY_UI, #SENSOR_DELAY_GAME, #SENSOR_DELAY_FASTEST or the delay in microseconds.

maxReportLatencyUs
Int32

Maximum time in microseconds that events can be delayed before being reported to the application. A large value allows reducing the power consumption associated with the sensor. If maxReportLatencyUs is set to zero, events are delivered as soon as they are available, which is equivalent to calling #registerListener(SensorEventListener, Sensor, int).

Returns

true if the sensor is supported and successfully enabled.

Attributes

Remarks

Registers a android.hardware.SensorEventListener SensorEventListener for the given sensor at the given sampling frequency and the given maximum reporting latency.

This function is similar to #registerListener(SensorEventListener, Sensor, int) but it allows events to stay temporarily in the hardware FIFO (queue) before being delivered. The events can be stored in the hardware FIFO up to maxReportLatencyUs microseconds. Once one of the events in the FIFO needs to be reported, all of the events in the FIFO are reported sequentially. This means that some events will be reported before the maximum reporting latency has elapsed.

When maxReportLatencyUs is 0, the call is equivalent to a call to #registerListener(SensorEventListener, Sensor, int), as it requires the events to be delivered as soon as possible.

When sensor.maxFifoEventCount() is 0, the sensor does not use a FIFO, so the call will also be equivalent to #registerListener(SensorEventListener, Sensor, int).

Setting maxReportLatencyUs to a positive value allows to reduce the number of interrupts the AP (Application Processor) receives, hence reducing power consumption, as the AP can switch to a lower power state while the sensor is capturing the data. This is especially important when registering to wake-up sensors, for which each interrupt causes the AP to wake up if it was in suspend mode. See Sensor#isWakeUpSensor() for more information on wake-up sensors.

<p class="note"> </p> Note: Don't use this method with one-shot trigger sensors such as Sensor#TYPE_SIGNIFICANT_MOTION. Use #requestTriggerSensor(TriggerEventListener, Sensor) instead. </p>

Java documentation for android.hardware.SensorManager.registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int, 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.

See also

Applies to

RegisterListener(ISensorEventListener, Sensor, SensorDelay, Handler)

Registers a android.hardware.SensorEventListener SensorEventListener for the given sensor.

[Android.Runtime.Register("registerListener", "(Landroid/hardware/SensorEventListener;Landroid/hardware/Sensor;ILandroid/os/Handler;)Z", "GetRegisterListener_Landroid_hardware_SensorEventListener_Landroid_hardware_Sensor_ILandroid_os_Handler_Handler")]
public virtual bool RegisterListener (Android.Hardware.ISensorEventListener? listener, Android.Hardware.Sensor? sensor, Android.Hardware.SensorDelay samplingPeriodUs, Android.OS.Handler? handler);
[<Android.Runtime.Register("registerListener", "(Landroid/hardware/SensorEventListener;Landroid/hardware/Sensor;ILandroid/os/Handler;)Z", "GetRegisterListener_Landroid_hardware_SensorEventListener_Landroid_hardware_Sensor_ILandroid_os_Handler_Handler")>]
abstract member RegisterListener : Android.Hardware.ISensorEventListener * Android.Hardware.Sensor * Android.Hardware.SensorDelay * Android.OS.Handler -> bool
override this.RegisterListener : Android.Hardware.ISensorEventListener * Android.Hardware.Sensor * Android.Hardware.SensorDelay * Android.OS.Handler -> bool

Parameters

listener
ISensorEventListener

A android.hardware.SensorEventListener SensorEventListener object.

sensor
Sensor

The android.hardware.Sensor Sensor to register to.

samplingPeriodUs
SensorDelay

The rate android.hardware.SensorEvent sensor events are delivered at. This is only a hint to the system. Events may be received faster or slower than the specified rate. Usually events are received faster. The value must be one of #SENSOR_DELAY_NORMAL, #SENSOR_DELAY_UI, #SENSOR_DELAY_GAME, or #SENSOR_DELAY_FASTEST or, the desired delay between events in microseconds. Specifying the delay in microseconds only works from Android 2.3 (API level 9) onwards. For earlier releases, you must use one of the SENSOR_DELAY_* constants.

handler
Handler

The android.os.Handler Handler the android.hardware.SensorEvent sensor events will be delivered to.

Returns

true if the sensor is supported and successfully enabled.

Attributes

Exceptions

when sensor is null or a trigger sensor

Remarks

Registers a android.hardware.SensorEventListener SensorEventListener for the given sensor. Events are delivered in continuous mode as soon as they are available. To reduce the power consumption, applications can use #registerListener(SensorEventListener, Sensor, int, int) instead and specify a positive non-zero maximum reporting latency. <p class="note"> </p> Note: Don't use this method with a one shot trigger sensor such as Sensor#TYPE_SIGNIFICANT_MOTION. Use #requestTriggerSensor(TriggerEventListener, Sensor) instead. </p>

Java documentation for android.hardware.SensorManager.registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int, android.os.Handler).

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.

See also

  • <xref:Android.Hardware.SensorManager.RegisterListener(Android.Hardware.ISensorEventListener%2c+Android.Hardware.Sensor%2c+Android.Hardware.Sensor)>
  • UnregisterListener(ISensorEventListener)
  • <xref:Android.Hardware.SensorManager.UnregisterListener(Android.Hardware.ISensorEventListener%2c+Android.Hardware.Sensor)>

Applies to

RegisterListener(ISensorEventListener, Sensor, SensorDelay)

Registers a android.hardware.SensorEventListener SensorEventListener for the given sensor at the given sampling frequency.

[Android.Runtime.Register("registerListener", "(Landroid/hardware/SensorEventListener;Landroid/hardware/Sensor;I)Z", "GetRegisterListener_Landroid_hardware_SensorEventListener_Landroid_hardware_Sensor_IHandler")]
public virtual bool RegisterListener (Android.Hardware.ISensorEventListener? listener, Android.Hardware.Sensor? sensor, Android.Hardware.SensorDelay samplingPeriodUs);
[<Android.Runtime.Register("registerListener", "(Landroid/hardware/SensorEventListener;Landroid/hardware/Sensor;I)Z", "GetRegisterListener_Landroid_hardware_SensorEventListener_Landroid_hardware_Sensor_IHandler")>]
abstract member RegisterListener : Android.Hardware.ISensorEventListener * Android.Hardware.Sensor * Android.Hardware.SensorDelay -> bool
override this.RegisterListener : Android.Hardware.ISensorEventListener * Android.Hardware.Sensor * Android.Hardware.SensorDelay -> bool

Parameters

listener
ISensorEventListener

A android.hardware.SensorEventListener SensorEventListener object.

sensor
Sensor

The android.hardware.Sensor Sensor to register to.

samplingPeriodUs
SensorDelay

The rate android.hardware.SensorEvent sensor events are delivered at. This is only a hint to the system. Events may be received faster or slower than the specified rate. Usually events are received faster. The value must be one of #SENSOR_DELAY_NORMAL, #SENSOR_DELAY_UI, #SENSOR_DELAY_GAME, or #SENSOR_DELAY_FASTEST or, the desired delay between events in microseconds. Specifying the delay in microseconds only works from Android 2.3 (API level 9) onwards. For earlier releases, you must use one of the SENSOR_DELAY_* constants.

Returns

true if the sensor is supported and successfully enabled.

Attributes

Exceptions

when sensor is null or a trigger sensor

Remarks

Registers a android.hardware.SensorEventListener SensorEventListener for the given sensor at the given sampling frequency.

The events will be delivered to the provided SensorEventListener as soon as they are available. To reduce the power consumption, applications can use #registerListener(SensorEventListener, Sensor, int, int) instead and specify a positive non-zero maximum reporting latency.

In the case of non-wake-up sensors, the events are only delivered while the Application Processor (AP) is not in suspend mode. See Sensor#isWakeUpSensor() for more details. To ensure delivery of events from non-wake-up sensors even when the screen is OFF, the application registering to the sensor must hold a partial wake-lock to keep the AP awake, otherwise some events might be lost while the AP is asleep. Note that although events might be lost while the AP is asleep, the sensor will still consume power if it is not explicitly deactivated by the application. Applications must unregister their SensorEventListeners in their activity's onPause() method to avoid consuming power while the device is inactive. See #registerListener(SensorEventListener, Sensor, int, int) for more details on hardware FIFO (queueing) capabilities and when some sensor events might be lost.

In the case of wake-up sensors, each event generated by the sensor will cause the AP to wake-up, ensuring that each event can be delivered. Because of this, registering to a wake-up sensor has very significant power implications. Call Sensor#isWakeUpSensor() to check whether a sensor is a wake-up sensor. See #registerListener(SensorEventListener, Sensor, int, int) for information on how to reduce the power impact of registering to wake-up sensors.

<p class="note"> Note: Don't use this method with one-shot trigger sensors such as Sensor#TYPE_SIGNIFICANT_MOTION. Use #requestTriggerSensor(TriggerEventListener, Sensor) instead. Use Sensor#getReportingMode() to obtain the reporting mode of a given sensor. </p>

Java documentation for android.hardware.SensorManager.registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, 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.

See also

  • <xref:Android.Hardware.SensorManager.RegisterListener(Android.Hardware.ISensorEventListener%2c+Android.Hardware.Sensor%2c+Android.Hardware.Sensor%2c+Android.Hardware.Sensor)>
  • UnregisterListener(ISensorEventListener)
  • <xref:Android.Hardware.SensorManager.UnregisterListener(Android.Hardware.ISensorEventListener%2c+Android.Hardware.Sensor)>

Applies to

RegisterListener(ISensorListener, Int32)

Caution

deprecated

Registers a listener for given sensors.

[Android.Runtime.Register("registerListener", "(Landroid/hardware/SensorListener;I)Z", "GetRegisterListener_Landroid_hardware_SensorListener_IHandler")]
[System.Obsolete("deprecated")]
public virtual bool RegisterListener (Android.Hardware.ISensorListener? listener, int sensors);
[<Android.Runtime.Register("registerListener", "(Landroid/hardware/SensorListener;I)Z", "GetRegisterListener_Landroid_hardware_SensorListener_IHandler")>]
[<System.Obsolete("deprecated")>]
abstract member RegisterListener : Android.Hardware.ISensorListener * int -> bool
override this.RegisterListener : Android.Hardware.ISensorListener * int -> bool

Parameters

listener
ISensorListener

sensor listener object

sensors
Int32

a bit masks of the sensors to register to

Returns

true if the sensor is supported and successfully enabled

Attributes

Remarks

Registers a listener for given sensors.

This member is deprecated. This method is deprecated, use SensorManager#registerListener(SensorEventListener, Sensor, int) instead.

Java documentation for android.hardware.SensorManager.registerListener(android.hardware.SensorListener, 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

RegisterListener(ISensorListener, Int32, SensorDelay)

Caution

deprecated

Registers a SensorListener for given sensors.

[Android.Runtime.Register("registerListener", "(Landroid/hardware/SensorListener;II)Z", "GetRegisterListener_Landroid_hardware_SensorListener_IIHandler")]
[System.Obsolete("deprecated")]
public virtual bool RegisterListener (Android.Hardware.ISensorListener? listener, int sensors, Android.Hardware.SensorDelay rate);
[<Android.Runtime.Register("registerListener", "(Landroid/hardware/SensorListener;II)Z", "GetRegisterListener_Landroid_hardware_SensorListener_IIHandler")>]
[<System.Obsolete("deprecated")>]
abstract member RegisterListener : Android.Hardware.ISensorListener * int * Android.Hardware.SensorDelay -> bool
override this.RegisterListener : Android.Hardware.ISensorListener * int * Android.Hardware.SensorDelay -> bool

Parameters

listener
ISensorListener

sensor listener object

sensors
Int32

a bit masks of the sensors to register to

rate
SensorDelay

rate of events. This is only a hint to the system. events may be received faster or slower than the specified rate. Usually events are received faster. The value must be one of #SENSOR_DELAY_NORMAL, #SENSOR_DELAY_UI, #SENSOR_DELAY_GAME, or #SENSOR_DELAY_FASTEST.

Returns

true if the sensor is supported and successfully enabled

Attributes

Remarks

Registers a SensorListener for given sensors.

This member is deprecated. This method is deprecated, use SensorManager#registerListener(SensorEventListener, Sensor, int) instead.

Java documentation for android.hardware.SensorManager.registerListener(android.hardware.SensorListener, int, 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