Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

# RangingSession.Callback

*** ** * ** ***

` public static interface RangingSession.Callback `   
` `

|---|
| android.ranging.RangingSession.Callback |

<br />

*** ** * ** ***

Callback interface for receiving ranging session events.

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/ranging/RangingSession.Callback#REASON_LOCAL_REQUEST` Indicates that the session was closed because `https://developer.android.com/reference/java/lang/AutoCloseable#close()` or `https://developer.android.com/reference/android/ranging/RangingSession#stop()` was called. |
| `int` | `https://developer.android.com/reference/android/ranging/RangingSession.Callback#REASON_NO_PEERS_FOUND` Indicates that the session was closed because none of the specified peers were found. |
| `int` | `https://developer.android.com/reference/android/ranging/RangingSession.Callback#REASON_REMOTE_REQUEST` Indicates that the session was closed at the request of a remote peer. |
| `int` | `https://developer.android.com/reference/android/ranging/RangingSession.Callback#REASON_SYSTEM_POLICY` Indicates that the local system policy forced the session to close, such as power management policy, airplane mode etc. |
| `int` | `https://developer.android.com/reference/android/ranging/RangingSession.Callback#REASON_UNKNOWN` Indicates that the session was closed due to an unknown reason. |
| `int` | `https://developer.android.com/reference/android/ranging/RangingSession.Callback#REASON_UNSUPPORTED` Indicates that the session closed because the provided session parameters were not supported. |

| ### Public methods ||
|---|---|
| ` abstract void` | ` https://developer.android.com/reference/android/ranging/RangingSession.Callback#onClosed(int)(int reason) ` Called when the ranging session has closed. |
| ` default void` | ` https://developer.android.com/reference/android/ranging/RangingSession.Callback#onDlTdoaResults(android.ranging.RangingDevice,%20android.ranging.DlTdoaMeasurement)(https://developer.android.com/reference/android/ranging/RangingDevice peer, https://developer.android.com/reference/android/ranging/DlTdoaMeasurement measurement) ` Called when DL-TDOA measurement data has been received from a peer. |
| ` default void` | ` https://developer.android.com/reference/android/ranging/RangingSession.Callback#onMotionReceived(android.ranging.RangingDevice,%20android.ranging.MotionState)(https://developer.android.com/reference/android/ranging/RangingDevice peer, https://developer.android.com/reference/android/ranging/MotionState motion) ` Called when the peer's motion state is received when a motion is detected from the previous reported motion change. |
| ` abstract void` | ` https://developer.android.com/reference/android/ranging/RangingSession.Callback#onOpenFailed(int)(int reason) ` Called when the ranging session failed to open. |
| ` abstract void` | ` https://developer.android.com/reference/android/ranging/RangingSession.Callback#onOpened()() ` Called when the ranging session opens successfully. |
| ` abstract void` | ` https://developer.android.com/reference/android/ranging/RangingSession.Callback#onResults(android.ranging.RangingDevice,%20android.ranging.RangingData)(https://developer.android.com/reference/android/ranging/RangingDevice peer, https://developer.android.com/reference/android/ranging/RangingData data) ` Called when ranging data has been received from a peer. |
| ` abstract void` | ` https://developer.android.com/reference/android/ranging/RangingSession.Callback#onStarted(android.ranging.RangingDevice,%20int)(https://developer.android.com/reference/android/ranging/RangingDevice peer, int technology) ` Called when ranging has started with a particular peer using a particular technology during an ongoing session. |
| ` abstract void` | ` https://developer.android.com/reference/android/ranging/RangingSession.Callback#onStopped(android.ranging.RangingDevice,%20int)(https://developer.android.com/reference/android/ranging/RangingDevice peer, int technology) ` Called when ranging has stopped with a particular peer using a particular technology during an ongoing session. |

## Constants

### REASON_LOCAL_REQUEST

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int REASON_LOCAL_REQUEST
```

Indicates that the session was closed because `https://developer.android.com/reference/java/lang/AutoCloseable#close()` or `https://developer.android.com/reference/android/ranging/RangingSession#stop()` was called.

<br />

Constant Value: 1 (0x00000001)

### REASON_NO_PEERS_FOUND

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int REASON_NO_PEERS_FOUND
```

Indicates that the session was closed because none of the specified peers were found.

<br />

Constant Value: 5 (0x00000005)

### REASON_REMOTE_REQUEST

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int REASON_REMOTE_REQUEST
```

Indicates that the session was closed at the request of a remote peer.

<br />

Constant Value: 2 (0x00000002)

### REASON_SYSTEM_POLICY

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int REASON_SYSTEM_POLICY
```

Indicates that the local system policy forced the session to close, such as power management policy, airplane mode etc.

<br />

Constant Value: 4 (0x00000004)

### REASON_UNKNOWN

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int REASON_UNKNOWN
```

Indicates that the session was closed due to an unknown reason.

<br />

Constant Value: 0 (0x00000000)

### REASON_UNSUPPORTED

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int REASON_UNSUPPORTED
```

Indicates that the session closed because the provided session parameters were not supported.

<br />

Constant Value: 3 (0x00000003)

## Public methods

### onClosed

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void onClosed (int reason)
```

Called when the ranging session has closed.

<br />

| Parameters ||
|---|---|
| `reason` | `int`: the reason why the session was closed, limited to values defined by `https://developer.android.com/`. <br /> |

### onDlTdoaResults

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onDlTdoaResults (RangingDevice peer, 
                DlTdoaMeasurement measurement)
```

Called when DL-TDOA measurement data has been received from a peer.

Only invoked when a DL-TDOA session has been started (i.e., `https://developer.android.com/reference/android/ranging/RangingPreference#getDeviceRole()` returns `https://developer.android.com/reference/android/ranging/RangingPreference#DEVICE_ROLE_DT_TAG`).

<br />

| Parameters ||
|---|---|
| `peer` | `RangingDevice`: `https://developer.android.com/reference/android/ranging/RangingDevice` the peer from which ranging data was received. This value cannot be `null`. <br /> |
| `measurement` | `DlTdoaMeasurement`: `https://developer.android.com/reference/android/ranging/DlTdoaMeasurement` the received measurement. This value cannot be `null`. <br /> |

### onMotionReceived

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onMotionReceived (RangingDevice peer, 
                MotionState motion)
```

Called when the peer's motion state is received when a motion is detected from the previous reported motion change.

<br />

| Parameters ||
|---|---|
| `peer` | `RangingDevice`: The peer device whose movement state has reported. This value cannot be `null`. <br /> |
| `motion` | `MotionState`: The new motion state of the peer. This value cannot be `null`. <br /> |

### onOpenFailed

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void onOpenFailed (int reason)
```

Called when the ranging session failed to open.

<br />

| Parameters ||
|---|---|
| `reason` | `int`: the reason for the failure, limited to values defined by `https://developer.android.com/`. <br /> |

### onOpened

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void onOpened ()
```

Called when the ranging session opens successfully.

<br />

### onResults

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void onResults (RangingDevice peer, 
                RangingData data)
```

Called when ranging data has been received from a peer.

<br />

| Parameters ||
|---|---|
| `peer` | `RangingDevice`: `https://developer.android.com/reference/android/ranging/RangingDevice` the peer from which ranging data was received. This value cannot be `null`. <br /> |
| `data` | `RangingData`: `https://developer.android.com/reference/android/ranging/RangingData` the received data. This value cannot be `null`. <br /> |

### onStarted

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void onStarted (RangingDevice peer, 
                int technology)
```

Called when ranging has started with a particular peer using a particular technology during an ongoing session.

<br />

| Parameters ||
|---|---|
| `peer` | `RangingDevice`: `https://developer.android.com/reference/android/ranging/RangingDevice` the peer with which ranging has started. This value cannot be `null`. <br /> |
| `technology` | `int`: `https://developer.android.com/` the ranging technology that started. <br /> |

### onStopped

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void onStopped (RangingDevice peer, 
                int technology)
```

Called when ranging has stopped with a particular peer using a particular technology during an ongoing session.

<br />

| Parameters ||
|---|---|
| `peer` | `RangingDevice`: `https://developer.android.com/reference/android/ranging/RangingDevice` the peer with which ranging has stopped. This value cannot be `null`. <br /> |
| `technology` | `int`: `https://developer.android.com/` the ranging technology that stopped. <br /> |