Java Code Examples for android.bluetooth.le.ScanSettings#SCAN_MODE_LOW_POWER
The following examples show how to use
android.bluetooth.le.ScanSettings#SCAN_MODE_LOW_POWER .
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 |
/** * 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: PeripheralScanner.java From bitgatt with Mozilla Public License 2.0 | 6 votes |
/** * This will start periodic scan with low power mode, please note that this will return false * if there is already a high-priority scan going on. * * @return true if scan started, false if not */ synchronized boolean startPeriodicScan(@Nullable Context context) { if (context == null) { Timber.v("Can't start a high priority scan with a null context"); return false; } if (stopPeriodicalScan || isScanning.get()) { Timber.v("Not starting periodical scan: isScanning: %b, was stopPeriodicalScan requested? %b", isScanning.get(), stopPeriodicalScan); return false; } Timber.d("Start Periodic Scan"); scanMode = ScanSettings.SCAN_MODE_LOW_POWER; scanBackoffMultiplier = DEFAULT_SCAN_BACKOFF_MULTIPLIER; periodicalScanEnabled.set(true); return startScan(context); }
Example 3
Source File: MockLollipopScanner.java From bitgatt with Mozilla Public License 2.0 | 5 votes |
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 4
Source File: MockLollipopScanner.java From bitgatt with Mozilla Public License 2.0 | 5 votes |
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(); }