Java Code Examples for android.bluetooth.BluetoothAdapter#startLeScan()

The following examples show how to use android.bluetooth.BluetoothAdapter#startLeScan() . 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
Source Project: RxCentralBle   File: JellyBeanScanner.java    License: Apache License 2.0 6 votes vote down vote up
private void startScan() {
  BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
  if (adapter != null && adapter.isEnabled()) {
    if (!adapter.startLeScan(leScanCallback)) {
      getErrorSubject().onError(new ConnectionError(SCAN_FAILED));

      if (RxCentralLogger.isError()) {
        RxCentralLogger.error("startLeScan failed.");
      }
    }
  } else {
    if (RxCentralLogger.isError()) {
      if (adapter == null) {
        RxCentralLogger.error("startScan - Default Bluetooth Adapter is null!");
      } else {
        RxCentralLogger.error("startScan - Bluetooth Adapter is disabled.");
      }
    }

    getErrorSubject().onError(new ConnectionError(SCAN_FAILED));
  }
}
 
Example 2
Source Project: neatle   File: LolipopLEScanner.java    License: MIT License 6 votes vote down vote up
@Override
@SuppressWarnings({"SpellCheckingInspection", "deprecation"})
protected void onStart(BluetoothAdapter adapter, int scanMode) {
    boolean ret;
    UUID uuids[] = scannerConfiguration.getServiceUUIDs();
    if (uuids.length > 0 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ret = adapter.startLeScan(uuids, callback);
    } else {
        ret = adapter.startLeScan(callback);
    }

    if (ret) {
        NeatleLogger.d("Bluetooth LE scan started.");
    } else {
        NeatleLogger.i("Bluetooth LE scan failed to start. State = " + adapter.getState());
    }
}
 
Example 3
public void startScan() {
    scanned.clear();
    BluetoothAdapter adapter = getAdapter();
    if (BuildConfig.DEBUG) {
        Log.d(L,"startLeScan, thread="+Thread.currentThread().getName()+", adapter="+(adapter==null?"null":"not null"));
    }
    if (adapter != null) {
        if (!isScanning(adapter)) {
            adapter.startLeScan(leScanCallback);
            isScanning = true;
        }
    }
}
 
Example 4
@Override
@RequiresPermission(allOf = {Manifest.permission.BLUETOOTH_ADMIN, Manifest.permission.BLUETOOTH})
public void run() {
	final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
	if (adapter != null && powerSaveRestInterval > 0 && powerSaveScanInterval > 0) {
		adapter.startLeScan(scanCallback);
		powerSaveHandler.postDelayed(powerSaveSleepTask, powerSaveScanInterval);
	}
}
 
Example 5
@SuppressWarnings("deprecation")
@Override
public void startScan(BluetoothAdapter adapter, List<ScanFilterCompat> filters, ScanSettingsCompat settings, ScanCallbackCompat callbackCompat) {
    adapter.startLeScan(registerCallback(filters, callbackCompat));
}
 
Example 6
@SuppressWarnings("deprecation")
@Override
public void startScan(BluetoothAdapter adapter, ScanCallbackCompat callbackCompat) {
    adapter.startLeScan(registerCallback(null, callbackCompat));
}