Java Code Examples for android.net.wifi.rtt.RangingRequest

The following examples show how to use android.net.wifi.rtt.RangingRequest. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private void startRangingRequest() {
    // Permission for fine location should already be granted via MainActivity (you can't get
    // to this class unless you already have permission. If they get to this class, then disable
    // fine location permission, we kick them back to main activity.
    if (ActivityCompat.checkSelfPermission(this, permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED) {
        finish();
    }

    mNumberOfRangeRequests++;

    RangingRequest rangingRequest =
            new RangingRequest.Builder().addAccessPoint(mScanResult).build();

    mWifiRttManager.startRanging(
            rangingRequest, getApplication().getMainExecutor(), mRttRangingResultCallback);
}
 
Example 2
Source Project: connectivity-samples   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
private List<ScanResult> find80211mcSupportedAccessPoints(
        @NonNull List<ScanResult> originalList) {
    List<ScanResult> newList = new ArrayList<>();

    for (ScanResult scanResult : originalList) {

        if (scanResult.is80211mcResponder()) {
            newList.add(scanResult);
        }

        if (newList.size() >= RangingRequest.getMaxPeers()) {
            break;
        }
    }
    return newList;
}
 
Example 3
public Single<List<RangingResult>> startRanging(
        @NonNull final ScanResult scanResult) {
    return Single.create(emitter -> {
        final RangingRequest request = new RangingRequest.Builder()
                .addAccessPoint(scanResult)
                .build();
        final RangingResultCallback callback = new RangingResultCallback() {
            @Override
            public void onRangingFailure(final int i) {
                emitter.onError(new RuntimeException("The WiFi-Ranging failed with error code: " + i));
            }

            @Override
            public void onRangingResults(final List<RangingResult> list) {
                emitter.onSuccess(list);
            }
        };
        rttManager.startRanging(request, mainExecutor, callback);
    });
}
 
Example 4
private void startRangingRequest() {
    // Permission for fine location should already be granted via MainActivity (you can't get
    // to this class unless you already have permission. If they get to this class, then disable
    // fine location permission, we kick them back to main activity.
    if (ActivityCompat.checkSelfPermission(this, permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED) {
        finish();
    }

    mNumberOfRangeRequests++;

    RangingRequest rangingRequest =
            new RangingRequest.Builder().addAccessPoint(mScanResult).build();

    mWifiRttManager.startRanging(
            rangingRequest, getApplication().getMainExecutor(), mRttRangingResultCallback);
}
 
Example 5
Source Project: android-WifiRttScan   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
private List<ScanResult> find80211mcSupportedAccessPoints(
        @NonNull List<ScanResult> originalList) {
    List<ScanResult> newList = new ArrayList<>();

    for (ScanResult scanResult : originalList) {

        if (scanResult.is80211mcResponder()) {
            newList.add(scanResult);
        }

        if (newList.size() >= RangingRequest.getMaxPeers()) {
            break;
        }
    }
    return newList;
}
 
Example 6
Source Project: WiFi-RTT-Trilateration   Source File: LocationRangingService.java    License: MIT License 5 votes vote down vote up
@SuppressLint("MissingPermission")
public void onReceive(Context context, Intent intent) {
    List<ScanResult> scanResults = mWifiManager.getScanResults();
    if (scanResults != null) {

        WifiRttAPs = new ArrayList<>();
        for (ScanResult scanResult : scanResults) {
            if (scanResult.is80211mcResponder())
                WifiRttAPs.add(scanResult);
            if (WifiRttAPs.size() >= RangingRequest.getMaxPeers()) {
                break;
            }
        }

        showMessage(scanResults.size()
                + " APs discovered, "
                + WifiRttAPs.size()
                + " RTT capable.");
        for (ScanResult wifiRttAP : WifiRttAPs) {
            showMessage("AP Supporting RTT: " + wifiRttAP.SSID + " (" + wifiRttAP.BSSID + ")");
        }
        //  Start ranging
        if (WifiRttAPs.size() < configuration.getConfiguration().size())
            showMessage("Did not find enough RTT enabled APs.  Found: " + WifiRttAPs.size());
        else {
            startRangingRequest(WifiRttAPs);
        }
    }
}
 
Example 7
Source Project: WiFi-RTT-Trilateration   Source File: LocationRangingService.java    License: MIT License 5 votes vote down vote up
@SuppressLint("MissingPermission")
private void startRangingRequest(List<ScanResult> scanResults) {
    RangingRequest rangingRequest =
            new RangingRequest.Builder().addAccessPoints(scanResults).build();

    mWifiRttManager.startRanging(
            rangingRequest, getApplication().getMainExecutor(), mRttRangingResultCallback);
}