With Android API-Level 21
, respectively 23 some methods to measure the Wifi roundtrip time
(RTT) were added to the SDK:
But I do not find any information how to use the API to measure the RTT
.
The relevant class RttManager is still marked as System API.
Is there any way to perform Device-To-AP RTT
measurement?
Starting with Android P
a public API for Wi-Fi RTT (IEEE 802.11mc) is now available.
WiFiRttManager
Add the following to your AndroidManifest:
<manifest ...>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-feature android:name="android.hardware.wifi.rtt" />
...
</manifest>
Get instance of WiFiRttManager:
final WifiRttManager rttManager = (WifiRttManager) context.getSystemService(Context.WIFI_RTT_RANGING_SERVICE);
Check if device supports Rtt measurements:
rttManager.isAvailable();
Perform a ranging:
// A ScanResult can be retrieved by e.g. perform a WiFi scan for WiFi's in range -> https://developer.android.com/reference/android/net/wifi/ScanResult.html
final RangingRequest request = new RangingRequest.Builder()
.addAccessPoint(scanResult)
.build();
final RangingResultCallback callback = new RangingResultCallback() {
public void onRangingResults(List<RangingResult> results) {
// Handle result, e.g. get distance to Access Point
}
public void onRangingFailure(int code) {
// Handle failure
}
};
// Start ranging and return result on main thread.
rttManager.startRanging(request, callback, null);
Please notice that the Access Point has to support Wi-Fi RTT (IEEE 802.11mc) as well!
Update: A sample app can be found here: Android Wifi RttManager sample
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With