com.polidea.rxandroidble.scan.ScanSettings Java Examples
The following examples show how to use
com.polidea.rxandroidble.scan.ScanSettings.
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: BluetoothClient.java From BLE-Indoor-Positioning with Apache License 2.0 | 5 votes |
public static void startScanning() { if (isScanning()) { return; } final BluetoothClient instance = getInstance(); Log.d(TAG, "Starting to scan for beacons"); ScanSettings scanSettings = new ScanSettings.Builder() .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY) .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES) .build(); instance.scanningSubscription = instance.rxBleClient.scanBleDevices(scanSettings) .subscribe(new Observer<ScanResult>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { Log.e(TAG, "Bluetooth scanning error", e); } @Override public void onNext(ScanResult scanResult) { instance.processScanResult(scanResult); } }); }
Example #2
Source File: Ob1G5CollectionService.java From xDrip with GNU General Public License v3.0 | 4 votes |
private synchronized void scan_for_device() { if (state == SCAN) { msg(gs(R.string.scanning)); stopScan(); tryLoadingSavedMAC(); // did we already find it? if (always_scan || scan_next_run || (transmitterMAC == null) || (!transmitterID.equals(transmitterIDmatchingMAC)) || (static_last_timestamp < 1)) { scan_next_run = false; // reset if set transmitterMAC = null; // reset if set last_scan_started = JoH.tsl(); scanWakeLock = JoH.getWakeLock("xdrip-jam-g5-scan", (int) Constants.MINUTE_IN_MS * 7); historicalTransmitterMAC = PersistentStore.getString(OB1G5_MACSTORE + transmitterID); // "" if unset ScanFilter filter; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && historicalTransmitterMAC.length() > 5) { filter = new ScanFilter.Builder() .setDeviceAddress(historicalTransmitterMAC) .build(); } else { final String localTransmitterID = transmitterID; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && localTransmitterID != null && localTransmitterID.length() > 4) { filter = new ScanFilter.Builder().setDeviceName(getTransmitterBluetoothName()).build(); } else { filter = new ScanFilter.Builder().build(); } } scanSubscription = new Subscription(rxBleClient.scanBleDevices( new ScanSettings.Builder() //.setScanMode(static_last_timestamp < 1 ? ScanSettings.SCAN_MODE_LOW_LATENCY : ScanSettings.SCAN_MODE_BALANCED) //.setCallbackType(ScanSettings.CALLBACK_TYPE_FIRST_MATCH) .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES) // TODO revisit scan mode .setScanMode(android_wear ? ScanSettings.SCAN_MODE_BALANCED : minimize_scanning ? ScanSettings.SCAN_MODE_BALANCED : ScanSettings.SCAN_MODE_LOW_LATENCY) // .setScanMode(ScanSettings.SCAN_MODE_BALANCED) .build(), // scan filter doesn't work reliable on android sdk 23+ filter ) // observe on? // do unsubscribe? //.doOnUnsubscribe(this::clearSubscription) .subscribeOn(Schedulers.io()) .subscribe(this::onScanResult, this::onScanFailure)); if (minimize_scanning) { // Must be less than fail over timeout Inevitable.task(STOP_SCAN_TASK_ID, 320 * Constants.SECOND_IN_MS, this::stopScanWithTimeoutAndReschedule); } UserError.Log.d(TAG, "Scanning for: " + getTransmitterBluetoothName()); } else { UserError.Log.d(TAG, "Transmitter mac already known: " + transmitterMAC); changeState(CONNECT); } } else { UserError.Log.wtf(TAG, "Attempt to scan when not in SCAN state"); } }
Example #3
Source File: Ob1G5CollectionService.java From xDrip with GNU General Public License v3.0 | 4 votes |
private synchronized void scan_for_device() { if (state == SCAN) { msg(gs(R.string.scanning)); stopScan(); tryLoadingSavedMAC(); // did we already find it? if (always_scan || scan_next_run || (transmitterMAC == null) || (!transmitterID.equals(transmitterIDmatchingMAC)) || (static_last_timestamp < 1)) { scan_next_run = false; // reset if set transmitterMAC = null; // reset if set last_scan_started = tsl(); scanWakeLock = JoH.getWakeLock("xdrip-jam-g5-scan", (int) Constants.MINUTE_IN_MS * 7); historicalTransmitterMAC = PersistentStore.getString(OB1G5_MACSTORE + transmitterID); // "" if unset ScanFilter filter; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && historicalTransmitterMAC.length() > 5) { filter = new ScanFilter.Builder() .setDeviceAddress(historicalTransmitterMAC) .build(); } else { final String localTransmitterID = transmitterID; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && localTransmitterID != null && localTransmitterID.length() > 4) { filter = new ScanFilter.Builder().setDeviceName(getTransmitterBluetoothName()).build(); } else { filter = new ScanFilter.Builder().build(); } } scanSubscription = new Subscription(rxBleClient.scanBleDevices( new ScanSettings.Builder() //.setScanMode(static_last_timestamp < 1 ? ScanSettings.SCAN_MODE_LOW_LATENCY : ScanSettings.SCAN_MODE_BALANCED) //.setCallbackType(ScanSettings.CALLBACK_TYPE_FIRST_MATCH) .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES) // TODO revisit scan mode .setScanMode(android_wear ? ScanSettings.SCAN_MODE_BALANCED : minimize_scanning ? ScanSettings.SCAN_MODE_BALANCED : ScanSettings.SCAN_MODE_LOW_LATENCY) // .setScanMode(ScanSettings.SCAN_MODE_BALANCED) .build(), // scan filter doesn't work reliable on android sdk 23+ filter ) // observe on? // do unsubscribe? //.doOnUnsubscribe(this::clearSubscription) .subscribeOn(Schedulers.io()) .subscribe(this::onScanResult, this::onScanFailure)); if (minimize_scanning) { // Must be less than fail over timeout Inevitable.task(STOP_SCAN_TASK_ID, 320 * Constants.SECOND_IN_MS, this::stopScanWithTimeoutAndReschedule); } UserError.Log.d(TAG, "Scanning for: " + getTransmitterBluetoothName()); } else { UserError.Log.d(TAG, "Transmitter mac already known: " + transmitterMAC); changeState(CONNECT); } } else { UserError.Log.wtf(TAG, "Attempt to scan when not in SCAN state"); } }
Example #4
Source File: Ob1G5CollectionService.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
private synchronized void scan_for_device() { if (state == SCAN) { msg(gs(R.string.scanning)); stopScan(); tryLoadingSavedMAC(); // did we already find it? if (always_scan || scan_next_run || (transmitterMAC == null) || (!transmitterID.equals(transmitterIDmatchingMAC)) || (static_last_timestamp < 1)) { scan_next_run = false; // reset if set transmitterMAC = null; // reset if set last_scan_started = JoH.tsl(); scanWakeLock = JoH.getWakeLock("xdrip-jam-g5-scan", (int) Constants.MINUTE_IN_MS * 7); historicalTransmitterMAC = PersistentStore.getString(OB1G5_MACSTORE + transmitterID); // "" if unset ScanFilter filter; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && historicalTransmitterMAC.length() > 5) { filter = new ScanFilter.Builder() .setDeviceAddress(historicalTransmitterMAC) .build(); } else { final String localTransmitterID = transmitterID; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && localTransmitterID != null && localTransmitterID.length() > 4) { filter = new ScanFilter.Builder().setDeviceName(getTransmitterBluetoothName()).build(); } else { filter = new ScanFilter.Builder().build(); } } scanSubscription = new Subscription(rxBleClient.scanBleDevices( new ScanSettings.Builder() //.setScanMode(static_last_timestamp < 1 ? ScanSettings.SCAN_MODE_LOW_LATENCY : ScanSettings.SCAN_MODE_BALANCED) //.setCallbackType(ScanSettings.CALLBACK_TYPE_FIRST_MATCH) .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES) // TODO revisit scan mode .setScanMode(android_wear ? ScanSettings.SCAN_MODE_BALANCED : minimize_scanning ? ScanSettings.SCAN_MODE_BALANCED : ScanSettings.SCAN_MODE_LOW_LATENCY) // .setScanMode(ScanSettings.SCAN_MODE_BALANCED) .build(), // scan filter doesn't work reliable on android sdk 23+ filter ) // observe on? // do unsubscribe? //.doOnUnsubscribe(this::clearSubscription) .subscribeOn(Schedulers.io()) .subscribe(this::onScanResult, this::onScanFailure)); if (minimize_scanning) { // Must be less than fail over timeout Inevitable.task(STOP_SCAN_TASK_ID, 320 * Constants.SECOND_IN_MS, this::stopScanWithTimeoutAndReschedule); } UserError.Log.d(TAG, "Scanning for: " + getTransmitterBluetoothName()); } else { UserError.Log.d(TAG, "Transmitter mac already known: " + transmitterMAC); changeState(CONNECT); } } else { UserError.Log.wtf(TAG, "Attempt to scan when not in SCAN state"); } }
Example #5
Source File: Ob1G5CollectionService.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
private synchronized void scan_for_device() { if (state == SCAN) { msg(gs(R.string.scanning)); stopScan(); tryLoadingSavedMAC(); // did we already find it? if (always_scan || scan_next_run || (transmitterMAC == null) || (!transmitterID.equals(transmitterIDmatchingMAC)) || (static_last_timestamp < 1)) { scan_next_run = false; // reset if set transmitterMAC = null; // reset if set last_scan_started = tsl(); scanWakeLock = JoH.getWakeLock("xdrip-jam-g5-scan", (int) Constants.MINUTE_IN_MS * 7); historicalTransmitterMAC = PersistentStore.getString(OB1G5_MACSTORE + transmitterID); // "" if unset ScanFilter filter; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && historicalTransmitterMAC.length() > 5) { filter = new ScanFilter.Builder() .setDeviceAddress(historicalTransmitterMAC) .build(); } else { final String localTransmitterID = transmitterID; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && localTransmitterID != null && localTransmitterID.length() > 4) { filter = new ScanFilter.Builder().setDeviceName(getTransmitterBluetoothName()).build(); } else { filter = new ScanFilter.Builder().build(); } } scanSubscription = new Subscription(rxBleClient.scanBleDevices( new ScanSettings.Builder() //.setScanMode(static_last_timestamp < 1 ? ScanSettings.SCAN_MODE_LOW_LATENCY : ScanSettings.SCAN_MODE_BALANCED) //.setCallbackType(ScanSettings.CALLBACK_TYPE_FIRST_MATCH) .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES) // TODO revisit scan mode .setScanMode(android_wear ? ScanSettings.SCAN_MODE_BALANCED : minimize_scanning ? ScanSettings.SCAN_MODE_BALANCED : ScanSettings.SCAN_MODE_LOW_LATENCY) // .setScanMode(ScanSettings.SCAN_MODE_BALANCED) .build(), // scan filter doesn't work reliable on android sdk 23+ filter ) // observe on? // do unsubscribe? //.doOnUnsubscribe(this::clearSubscription) .subscribeOn(Schedulers.io()) .subscribe(this::onScanResult, this::onScanFailure)); if (minimize_scanning) { // Must be less than fail over timeout Inevitable.task(STOP_SCAN_TASK_ID, 320 * Constants.SECOND_IN_MS, this::stopScanWithTimeoutAndReschedule); } UserError.Log.d(TAG, "Scanning for: " + getTransmitterBluetoothName()); } else { UserError.Log.d(TAG, "Transmitter mac already known: " + transmitterMAC); changeState(CONNECT); } } else { UserError.Log.wtf(TAG, "Attempt to scan when not in SCAN state"); } }