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

The following examples show how to use android.bluetooth.BluetoothAdapter#startLeScan() . 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: JellyBeanScanner.java    From RxCentralBle with 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 File: LolipopLEScanner.java    From neatle with 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
Source File: BLECentralManagerDefault.java    From itag with GNU General Public License v3.0 5 votes vote down vote up
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
Source File: BluetoothLeScannerImplJB.java    From Android-Scanner-Compat-Library with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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
Source File: BluetoothLeScannerCompat.java    From AndroidBleManager with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void startScan(BluetoothAdapter adapter, List<ScanFilterCompat> filters, ScanSettingsCompat settings, ScanCallbackCompat callbackCompat) {
    adapter.startLeScan(registerCallback(filters, callbackCompat));
}
 
Example 6
Source File: BluetoothLeScannerCompat.java    From AndroidBleManager with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void startScan(BluetoothAdapter adapter, ScanCallbackCompat callbackCompat) {
    adapter.startLeScan(registerCallback(null, callbackCompat));
}