RangingSession


class RangingSession : AutoCloseable
kotlin.Any
   ↳ android.ranging.RangingSession

Represents a session for performing ranging operations. A RangingSession manages the lifecycle of a ranging operation, including start, stop, and event callbacks.

All methods are asynchronous and rely on the provided Executor to invoke callbacks on appropriate threads.

This class implements AutoCloseable, ensuring that resources can be automatically released when the session is closed.

Summary

Nested classes
abstract

Callback interface for receiving ranging session events.

Public methods
Unit

Adds a new device to an ongoing ranging session.

Unit

Closes this resource, relinquishing any underlying resources.

Unit
reconfigureRangingInterval(intervalSkipCount: Int)

Reconfigures the ranging interval for the current session by setting the interval skip count.

Unit

Removes a specific device from an ongoing ranging session.

CancellationSignal
start(rangingPreference: RangingPreference)

Starts the ranging session with the provided ranging preferences.

Unit

Stops the ranging session.

String

Public methods

addDeviceToRangingSession

fun addDeviceToRangingSession(deviceRangingParams: RangingConfig): Unit

Adds a new device to an ongoing ranging session.

This method allows for adding a new device to an active ranging session using either raw or out-of-band (OOB) ranging parameters. Only devices represented by RawResponderRangingConfig or OobResponderRangingConfig are supported. If the provided RangingConfig does not match one of these types, the addition fails and invokes Callback.onOpenFailed(int) with a reason of Callback.REASON_UNSUPPORTED.


Requires android.Manifest.permission.RANGING
Parameters
deviceRangingParams RangingConfig: the ranging parameters for the device to be added, which must be an instance of either RawResponderRangingConfig or OobResponderRangingConfig. This value cannot be null.

close

fun close(): Unit

Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement. Requires android.Manifest.permission.RANGING

Exceptions
java.lang.Exception if this resource cannot be closed

reconfigureRangingInterval

fun reconfigureRangingInterval(intervalSkipCount: Int): Unit

Reconfigures the ranging interval for the current session by setting the interval skip count. The intervalSkipCount defines how many intervals should be skipped between successive ranging rounds. Valid values range from 0 to 255.
Requires android.Manifest.permission.RANGING

Parameters
intervalSkipCount Int: the number of intervals to skip, ranging from 0 to 255. Value is between 0 and 255 inclusive

removeDeviceFromRangingSession

fun removeDeviceFromRangingSession(rangingDevice: RangingDevice): Unit

Removes a specific device from an ongoing ranging session.

This method removes a specified device from the active ranging session, stopping further ranging operations for that device. The operation is handled by the system server and may throw a RemoteException in case of server-side communication issues.


Requires android.Manifest.permission.RANGING
Parameters
rangingDevice RangingDevice: the device to be removed from the session. This value cannot be null.

start

fun start(rangingPreference: RangingPreference): CancellationSignal

Starts the ranging session with the provided ranging preferences.

The Callback.onOpened() will be called when the session finishes starting.

The provided RangingPreference determines the configuration for the session. A CancellationSignal is returned to allow the caller to cancel the session if needed. If the session is canceled, the close() method will be invoked automatically to release resources.
Requires android.Manifest.permission.RANGING

Parameters
rangingPreference RangingPreference: RangingPreference the preferences for configuring the ranging session. This value cannot be null.
Return
CancellationSignal a CancellationSignal to close the session. This value cannot be null.

stop

fun stop(): Unit

Stops the ranging session.

This method releases any ongoing ranging operations. If the operation fails, it will propagate a RemoteException from the system server.
Requires android.Manifest.permission.RANGING

toString

fun toString(): String
Return
String a string representation of the object.