WifiRttManager

open class WifiRttManager
kotlin.Any
   ↳ android.net.wifi.rtt.WifiRttManager

This class provides the primary API for measuring distance (range) to other devices using the IEEE 802.11mc Wi-Fi Round Trip Time (RTT) technology.

The devices which can be ranged include:

  • Access Points (APs)
  • Wi-Fi Aware peers

    Ranging requests are triggered using #startRanging(RangingRequest, Executor, RangingResultCallback). Results (in case of successful operation) are returned in the RangingResultCallback#onRangingResults(List) callback.

    Wi-Fi RTT may not be usable at some points, e.g. when Wi-Fi is disabled. To validate that the functionality is available use the #isAvailable() function. To track changes in RTT usability register for the #ACTION_WIFI_RTT_STATE_CHANGED broadcast. Note that this broadcast is not sticky - you should register for it and then check the above API to avoid a race condition.
    Requires API level 28 (Android 8.+, P)

  • Summary

    Constants
    static String

    Broadcast intent action to indicate that the state of Wi-Fi RTT availability has changed.

    Public methods
    open Unit
    startRanging(request: RangingRequest, executor: Executor, callback: RangingResultCallback)

    Initiate a request to range to a set of devices specified in the RangingRequest.

    open Boolean

    Returns the current status of RTT API: whether or not RTT is available.

    Constants

    ACTION_WIFI_RTT_STATE_CHANGED

    added in API level 28
    static val ACTION_WIFI_RTT_STATE_CHANGED: String

    Broadcast intent action to indicate that the state of Wi-Fi RTT availability has changed. Use the #isAvailable() to query the current status. This broadcast is not sticky, use the #isAvailable() API after registering the broadcast to check the current state of Wi-Fi RTT.

    Note: The broadcast is only delivered to registered receivers - no manifest registered components will be launched.
    Requires API level 28 (Android 8.+, P)

    Value: "android.net.wifi.rtt.action.WIFI_RTT_STATE_CHANGED"

    Public methods

    startRanging

    added in API level 28
    open fun startRanging(request: RangingRequest, executor: Executor, callback: RangingResultCallback): Unit

    Initiate a request to range to a set of devices specified in the RangingRequest. Results will be returned in the RangingResultCallback set of callbacks.
    Requires android.Manifest.permission#ACCESS_FINE_LOCATION and android.Manifest.permission#CHANGE_WIFI_STATE and android.Manifest.permission#ACCESS_WIFI_STATE
    Requires API level 28 (Android 8.+, P)

    Parameters
    request RangingRequest: A request specifying a set of devices whose distance measurements are requested. This value must never be null.
    executor RangingRequest: The Executor on which to run the callback. This value must never be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context#getMainExecutor(). To dispatch events through a shared thread pool, you can use AsyncTask#THREAD_POOL_EXECUTOR.
    callback RangingRequest: A callback for the result of the ranging request. This value must never be null.

    isAvailable

    added in API level 28
    open fun isAvailable(): Boolean

    Returns the current status of RTT API: whether or not RTT is available. To track changes in the state of RTT API register for the #ACTION_WIFI_RTT_STATE_CHANGED broadcast.

    Note: availability of RTT does not mean that the app can use the API. The app's permissions and platform Location Mode are validated at run-time.
    Requires API level 28 (Android 8.+, P)

    Return
    Boolean: A boolean indicating whether the app can use the RTT API at this time (true) or not (false).