Java Code Examples for android.bluetooth.le.ScanSettings#SCAN_MODE_BALANCED

The following examples show how to use android.bluetooth.le.ScanSettings#SCAN_MODE_BALANCED . 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
Source File: BluetoothCentral.java    From blessed-android with MIT License 6 votes vote down vote up
/**
 * Set the default scanMode.
 *
 * <p>Must be ScanSettings.SCAN_MODE_LOW_POWER, ScanSettings.SCAN_MODE_LOW_LATENCY, ScanSettings.SCAN_MODE_BALANCED or ScanSettings.SCAN_MODE_OPPORTUNISTIC.
 * The default value is SCAN_MODE_LOW_LATENCY.
 *
 * @param scanMode the scanMode to set
 * @return true if a valid scanMode was provided, otherwise false
 */
public boolean setScanMode(int scanMode) {
    if (scanMode == ScanSettings.SCAN_MODE_LOW_POWER ||
            scanMode == ScanSettings.SCAN_MODE_LOW_LATENCY ||
            scanMode == ScanSettings.SCAN_MODE_BALANCED ||
            scanMode == ScanSettings.SCAN_MODE_OPPORTUNISTIC) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            this.scanSettings = new ScanSettings.Builder()
                    .setScanMode(scanMode)
                    .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
                    .setMatchMode(ScanSettings.MATCH_MODE_AGGRESSIVE)
                    .setNumOfMatches(ScanSettings.MATCH_NUM_ONE_ADVERTISEMENT)
                    .setReportDelay(0L)
                    .build();
        } else {
            this.scanSettings = new ScanSettings.Builder()
                    .setScanMode(scanMode)
                    .setReportDelay(0L)
                    .build();
        }
        return true;
    }
    return false;
}
 
Example 2
Source File: MockLollipopScanner.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
public void startScanForIntent(PendingIntent callbackIntent, ScanSettings settings, List<ScanFilter> filters, String packageName) {
    singleThreadExecutor.schedule(resultsRunnable, TIME_BETWEEN_RESULTS, TimeUnit.MILLISECONDS);
    if (settings.getScanMode() == ScanSettings.SCAN_MODE_LOW_LATENCY) {
        currentScanState = ScanState.INTENT_SCANNING;
    } else if (settings.getScanMode() == ScanSettings.SCAN_MODE_BALANCED) {
        currentScanState = ScanState.INTENT_SCANNING;
    } else if (settings.getScanMode() == ScanSettings.SCAN_MODE_LOW_POWER) {
        currentScanState = ScanState.INTENT_SCANNING;
    }
}
 
Example 3
Source File: MockLollipopScanner.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
public void startScan(int mScannerId, ScanSettings mSettings, List<ScanFilter> mFilters, List<List<ResultStorageDescriptor>> mResultStorages, String packageName) {
    if (mSettings.getScanMode() == ScanSettings.SCAN_MODE_LOW_LATENCY) {
        currentScanState = ScanState.LOW_LATENCY;
    } else if (mSettings.getScanMode() == ScanSettings.SCAN_MODE_BALANCED) {
        currentScanState = ScanState.BALANCED_LATENCY;
    } else if (mSettings.getScanMode() == ScanSettings.SCAN_MODE_LOW_POWER) {
        currentScanState = ScanState.HIGH_LATENCY;
    }
    Timber.v("Current scan state: %s", currentScanState);
    SystemClock.sleep(TIME_BETWEEN_RESULTS);
    resultsRunnable.run();
}