com.polidea.rxandroidble2.scan.ScanResult Java Examples

The following examples show how to use com.polidea.rxandroidble2.scan.ScanResult. 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: BackgroundScannerImpl.java    From RxAndroidBle with Apache License 2.0 6 votes vote down vote up
@Override
public List<ScanResult> onScanResultReceived(@NonNull Intent intent) {
    final int callbackType = intent.getIntExtra(BluetoothLeScanner.EXTRA_CALLBACK_TYPE, -1);
    final int errorCode = intent.getIntExtra(BluetoothLeScanner.EXTRA_ERROR_CODE, NO_ERROR);
    final List<android.bluetooth.le.ScanResult> nativeScanResults = extractScanResults(intent);
    ArrayList<ScanResult> scanResults = new ArrayList<>();

    if (errorCode == NO_ERROR) {
        for (android.bluetooth.le.ScanResult result : nativeScanResults) {
            scanResults.add(convertScanResultToRxAndroidBLEModel(callbackType, result));
        }

        return scanResults;
    } else {
        throw new BleScanException(errorCode);
    }
}
 
Example #2
Source File: InPenScanMeister.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected synchronized void onScanResult(ScanResult bleScanResult) {

    final String this_address = bleScanResult.getBleDevice().getMacAddress();
    final byte[] scanRecordBytes = bleScanResult.getScanRecord().getBytes();

    if (D) UserError.Log.d(TAG, JoH.bytesToHex(bleScanResult.getScanRecord().getBytes()));

    if (scanRecordBytes != null && scanRecordBytes.length > 0) {
        PersistentStore.setBytes(STORE_INPEN_ADVERT + this_address, scanRecordBytes);
    }
    stopScan("Got match");
    JoH.threadSleep(500);
    processCallBacks(this_address, "SCAN_FOUND");
    releaseWakeLock();
}
 
Example #3
Source File: PendiqService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private synchronized void onScanResult(ScanResult bleScanResult) {
    final int rssi = bleScanResult.getRssi();
    if (rssi > MINIMUM_RSSI) {
        final String this_name = bleScanResult.getBleDevice().getName();
        final boolean matches = isPendiqName(this_name);

        // TODO build list of candidates for processing and start inevitable task to poll them
        // TODO use AutoConnect if only one?
        UserError.Log.d(TAG, "Found a device with name: " + this_name + " rssi: " + rssi + "  " + (matches ? "-> MATCH" : ""));
        if (matches) {
            stopScan();
            address = bleScanResult.getBleDevice().getMacAddress();
            name = this_name;
            UserError.Log.d(TAG, "Set address to: " + address);
            if (auto_connect) {
                changeState(CONNECT);
            } else {
                changeState(CONNECT_NOW);
            }
        }
    } else {
        if (JoH.quietratelimit("log-low-rssi", 2)) {
            UserError.Log.d(TAG, "Low rssi device: " + bleScanResult.getBleDevice().getMacAddress());
        }
    }
}
 
Example #4
Source File: RxBleClientImpl.java    From RxAndroidBle with Apache License 2.0 6 votes vote down vote up
@Override
public Observable<ScanResult> scanBleDevices(final ScanSettings scanSettings, final ScanFilter... scanFilters) {
    return Observable.defer(new Callable<ObservableSource<? extends ScanResult>>() {
        @Override
        public Observable<ScanResult> call() {
            scanPreconditionVerifier.verify(scanSettings.shouldCheckLocationProviderState());
            final ScanSetup scanSetup = scanSetupBuilder.build(scanSettings, scanFilters);
            final Operation<RxBleInternalScanResult> scanOperation = scanSetup.scanOperation;
            return operationQueue.queue(scanOperation)
                    .unsubscribeOn(bluetoothInteractionScheduler)
                    .compose(scanSetup.scanOperationBehaviourEmulatorTransformer)
                    .map(internalToExternalScanResultMapFunction)
                    .doOnNext(new Consumer<ScanResult>() {
                        @Override
                        public void accept(ScanResult scanResult) {
                            if (RxBleLog.getShouldLogScannedPeripherals()) RxBleLog.i("%s", scanResult);
                        }
                    })
                    .mergeWith(RxBleClientImpl.this.<ScanResult>bluetoothAdapterOffExceptionObservable());
        }
    });
}
 
Example #5
Source File: InPenScanMeister.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected synchronized void onScanResult(ScanResult bleScanResult) {

    final String this_address = bleScanResult.getBleDevice().getMacAddress();
    final byte[] scanRecordBytes = bleScanResult.getScanRecord().getBytes();

    if (D) UserError.Log.d(TAG, JoH.bytesToHex(bleScanResult.getScanRecord().getBytes()));

    if (scanRecordBytes != null && scanRecordBytes.length > 0) {
        PersistentStore.setBytes(STORE_INPEN_ADVERT + this_address, scanRecordBytes);
    }
    stopScan("Got match");
    JoH.threadSleep(500);
    processCallBacks(this_address, "SCAN_FOUND");
    releaseWakeLock();
}
 
Example #6
Source File: ScanResultsAdapter.java    From RxAndroidBle with Apache License 2.0 6 votes vote down vote up
void addScanResult(ScanResult bleScanResult) {
    // Not the best way to ensure distinct devices, just for sake on the demo.

    for (int i = 0; i < data.size(); i++) {

        if (data.get(i).getBleDevice().equals(bleScanResult.getBleDevice())) {
            data.set(i, bleScanResult);
            notifyItemChanged(i);
            return;
        }
    }

    data.add(bleScanResult);
    Collections.sort(data, SORTING_COMPARATOR);
    notifyDataSetChanged();
}
 
Example #7
Source File: PendiqService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private synchronized void onScanResult(ScanResult bleScanResult) {
    final int rssi = bleScanResult.getRssi();
    if (rssi > MINIMUM_RSSI) {
        final String this_name = bleScanResult.getBleDevice().getName();
        final boolean matches = isPendiqName(this_name);

        // TODO build list of candidates for processing and start inevitable task to poll them
        // TODO use AutoConnect if only one?
        UserError.Log.d(TAG, "Found a device with name: " + this_name + " rssi: " + rssi + "  " + (matches ? "-> MATCH" : ""));
        if (matches) {
            stopScan();
            address = bleScanResult.getBleDevice().getMacAddress();
            name = this_name;
            UserError.Log.d(TAG, "Set address to: " + address);
            if (auto_connect) {
                changeState(CONNECT);
            } else {
                changeState(CONNECT_NOW);
            }
        }
    } else {
        if (JoH.quietratelimit("log-low-rssi", 2)) {
            UserError.Log.d(TAG, "Low rssi device: " + bleScanResult.getBleDevice().getMacAddress());
        }
    }
}
 
Example #8
Source File: Scanner.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected synchronized void onScanResult(ScanResult bleScanResult) {

    if (address == null) {
        UserError.Log.d(TAG, "Address has been set to null, stopping scan.");
        stopScan("Address nulled");
        return;
    }
    final String this_address = bleScanResult.getBleDevice().getMacAddress();

    boolean matches = this_address.equals(address);


    if (matches) {
        stopScan("Got match");

        processDataFromScanRecord(bleScanResult.getScanRecord());

        JoH.threadSleep(500);
        processCallBacks(this_address, "SCAN_FOUND");
        releaseWakeLock();
    }

    if (JoH.quietratelimit("scan-debug-result", 5)) {
        UserError.Log.d(TAG, "Found device: " + this_address + (matches ? "  MATCH" : ""));
    }

}
 
Example #9
Source File: BackgroundScanReceiver.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onReceive(Context context, Intent intent) {

    final String action = intent.getAction();

    android.util.Log.d("BackgroundScanReceiver", "GOT SCAN INTENT!! " + action);

    if (action != null && action.equals(ACTION_NAME)) {

        String caller = intent.getStringExtra(CALLING_CLASS);
        if (caller == null) caller = this.getClass().getSimpleName();

        // TODO by class name?
        final BackgroundScanner backgroundScanner = RxBleProvider.getSingleton().getBackgroundScanner();
        try {
            final List<ScanResult> scanResults = backgroundScanner.onScanResultReceived(intent);
            final String matchedMac = scanResults.get(0).getBleDevice().getMacAddress();
            final String matchedName = scanResults.get(0).getBleDevice().getName();
            final boolean calledBack = processCallbacks(caller, matchedMac, matchedName, SCAN_FOUND_CALLBACK);
            UserError.Log.d(caller, "Scan results received: " + matchedMac + " " + scanResults);
            if (!calledBack) {
                try {
                    // bit of an ugly fix to system wide persistent nature of background scans and lack of proper support for one hit over various android devices
                    backgroundScanner.stopBackgroundBleScan(PendingIntent.getBroadcast(xdrip.getAppContext(), 142, // must match original
                            intent, PendingIntent.FLAG_UPDATE_CURRENT));
                } catch (Exception e) {
                    //
                }
            }
        } catch (NullPointerException | BleScanException exception) {
            UserError.Log.e(caller, "Failed to scan devices" + exception);
        }

    }

    // ignore invalid actions
}
 
Example #10
Source File: Scanner.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected synchronized void onScanResult(ScanResult bleScanResult) {

    if (address == null) {
        UserError.Log.d(TAG, "Address has been set to null, stopping scan.");
        stopScan("Address nulled");
        return;
    }
    final String this_address = bleScanResult.getBleDevice().getMacAddress();

    boolean matches = this_address.equals(address);


    if (matches) {
        stopScan("Got match");

        processDataFromScanRecord(bleScanResult.getScanRecord());

        JoH.threadSleep(500);
        processCallBacks(this_address, "SCAN_FOUND");
        releaseWakeLock();
    }

    if (JoH.quietratelimit("scan-debug-result", 5)) {
        UserError.Log.d(TAG, "Found device: " + this_address + (matches ? "  MATCH" : ""));
    }

}
 
Example #11
Source File: BackgroundScanReceiver.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onReceive(Context context, Intent intent) {

    final String action = intent.getAction();

    android.util.Log.d("BackgroundScanReceiver", "GOT SCAN INTENT!! " + action);

    if (action != null && action.equals(ACTION_NAME)) {

        String caller = intent.getStringExtra(CALLING_CLASS);
        if (caller == null) caller = this.getClass().getSimpleName();

        // TODO by class name?
        final BackgroundScanner backgroundScanner = RxBleProvider.getSingleton().getBackgroundScanner();
        try {
            final List<ScanResult> scanResults = backgroundScanner.onScanResultReceived(intent);
            final String matchedMac = scanResults.get(0).getBleDevice().getMacAddress();
            final String matchedName = scanResults.get(0).getBleDevice().getName();
            final boolean calledBack = processCallbacks(caller, matchedMac, matchedName, SCAN_FOUND_CALLBACK);
            UserError.Log.d(caller, "Scan results received: " + matchedMac + " " + scanResults);
            if (!calledBack) {
                try {
                    // bit of an ugly fix to system wide persistent nature of background scans and lack of proper support for one hit over various android devices
                    backgroundScanner.stopBackgroundBleScan(PendingIntent.getBroadcast(xdrip.getAppContext(), 142, // must match original
                            intent, PendingIntent.FLAG_UPDATE_CURRENT));
                } catch (Exception e) {
                    //
                }
            }
        } catch (NullPointerException | BleScanException exception) {
            UserError.Log.e(caller, "Failed to scan devices" + exception);
        }

    }

    // ignore invalid actions
}
 
Example #12
Source File: ScanReceiver.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@RequiresApi(26 /* Build.VERSION_CODES.O */)
@Override
public void onReceive(Context context, Intent intent) {
    BackgroundScanner backgroundScanner = SampleApplication.getRxBleClient(context).getBackgroundScanner();

    try {
        final List<ScanResult> scanResults = backgroundScanner.onScanResultReceived(intent);
        Log.i("ScanReceiver", "Scan results received: " + scanResults);
    } catch (BleScanException exception) {
        Log.w("ScanReceiver", "Failed to scan devices", exception);
    }
}
 
Example #13
Source File: ScanActivity.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
private void configureResultList() {
    recyclerView.setHasFixedSize(true);
    recyclerView.setItemAnimator(null);
    LinearLayoutManager recyclerLayoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(recyclerLayoutManager);
    resultsAdapter = new ScanResultsAdapter();
    recyclerView.setAdapter(resultsAdapter);
    resultsAdapter.setOnAdapterItemClickListener(view -> {
        final int childAdapterPosition = recyclerView.getChildAdapterPosition(view);
        final ScanResult itemAtPosition = resultsAdapter.getItemAtPosition(childAdapterPosition);
        onAdapterItemClick(itemAtPosition);
    });
}
 
Example #14
Source File: ScanResultsAdapter.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
    final ScanResult rxBleScanResult = data.get(position);
    final RxBleDevice bleDevice = rxBleScanResult.getBleDevice();
    holder.line1.setText(String.format(Locale.getDefault(), "%s (%s)", bleDevice.getMacAddress(), bleDevice.getName()));
    holder.line2.setText(String.format(Locale.getDefault(), "RSSI: %d", rxBleScanResult.getRssi()));
}
 
Example #15
Source File: RxBleClientImpl.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@Inject
RxBleClientImpl(RxBleAdapterWrapper rxBleAdapterWrapper,
                ClientOperationQueue operationQueue,
                Observable<BleAdapterState> adapterStateObservable,
                UUIDUtil uuidUtil,
                LocationServicesStatus locationServicesStatus,
                Lazy<ClientStateObservable> lazyClientStateObservable,
                RxBleDeviceProvider rxBleDeviceProvider,
                ScanSetupBuilder scanSetupBuilder,
                ScanPreconditionsVerifier scanPreconditionVerifier,
                Function<RxBleInternalScanResult, ScanResult> internalToExternalScanResultMapFunction,
                @Named(ClientComponent.NamedSchedulers.BLUETOOTH_INTERACTION) Scheduler bluetoothInteractionScheduler,
                ClientComponent.ClientComponentFinalizer clientComponentFinalizer,
                BackgroundScanner backgroundScanner,
                CheckerLocationPermission checkerLocationPermission) {
    this.uuidUtil = uuidUtil;
    this.operationQueue = operationQueue;
    this.rxBleAdapterWrapper = rxBleAdapterWrapper;
    this.rxBleAdapterStateObservable = adapterStateObservable;
    this.locationServicesStatus = locationServicesStatus;
    this.lazyClientStateObservable = lazyClientStateObservable;
    this.rxBleDeviceProvider = rxBleDeviceProvider;
    this.scanSetupBuilder = scanSetupBuilder;
    this.scanPreconditionVerifier = scanPreconditionVerifier;
    this.internalToExternalScanResultMapFunction = internalToExternalScanResultMapFunction;
    this.bluetoothInteractionScheduler = bluetoothInteractionScheduler;
    this.clientComponentFinalizer = clientComponentFinalizer;
    this.backgroundScanner = backgroundScanner;
    this.checkerLocationPermission = checkerLocationPermission;
}
 
Example #16
Source File: InternalToExternalScanResultConverter.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@Override
public ScanResult apply(RxBleInternalScanResult rxBleInternalScanResult) {
    return new ScanResult(
            deviceProvider.getBleDevice(rxBleInternalScanResult.getBluetoothDevice().getAddress()),
            rxBleInternalScanResult.getRssi(),
            rxBleInternalScanResult.getTimestampNanos(),
            rxBleInternalScanResult.getScanCallbackType(),
            rxBleInternalScanResult.getScanRecord()
    );
}
 
Example #17
Source File: ScanActivity.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
private void onAdapterItemClick(ScanResult scanResults) {
    final String macAddress = scanResults.getBleDevice().getMacAddress();
    final Intent intent = new Intent(this, DeviceActivity.class);
    intent.putExtra(DeviceActivity.EXTRA_MAC_ADDRESS, macAddress);
    startActivity(intent);
}
 
Example #18
Source File: RxBleClientMock.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<ScanResult> scanBleDevices(ScanSettings scanSettings, ScanFilter... scanFilters) {
    return Observable.error(new RuntimeException("not implemented")); // TODO [DS]
}
 
Example #19
Source File: ScanMeister.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
protected synchronized void onScanResult(ScanResult bleScanResult) {

        if (!wideSearch && address == null && name == null) {
            UserError.Log.d(TAG, "Address has been set to null, stopping scan.");
            stopScan("Address nulled");
            return;
        }

        try {
            for (ParcelUuid p : bleScanResult.getScanRecord().getServiceUuids()) {
                UserError.Log.d(TAG,"SERVICE: "+p.getUuid());
            }

        } catch (Exception e) {
            //
        }
        final int rssi = bleScanResult.getRssi();
        if (rssi > MINIMUM_RSSI) {
            //final String this_name = bleScanResult.getBleDevice().getName();
            final String this_address = bleScanResult.getBleDevice().getMacAddress();
            String this_name = "";
            if (name != null || customFilter != null) {
                this_name = bleScanResult.getBleDevice().getName();
            }
            final boolean matches = (customFilter != null)
                    || ((address != null && address.equalsIgnoreCase(this_address))
                    || (name != null && this_name != null && name.contains(this_name)));
            if (matches || JoH.quietratelimit("scanmeister-show-result", 2)) {
                UserError.Log.d(TAG, "Found a device: " + this_address + " " + this_name + " rssi: " + rssi + "  " + (matches ? "-> MATCH" : ""));
            }
            if (matches && stopOnFirstMatch) {
                stopScan("Got match");
                JoH.threadSleep(500);
                processCallBacks(this_address, SCAN_FOUND_CALLBACK);
                releaseWakeLock();
            }
            if (matches && !stopOnFirstMatch) {
                // TODO deposit good information in bundle - TODO: dry
                processCallBacks(this_address, SCAN_FOUND_CALLBACK, this_name, null);
            }

        } else {
            if (JoH.quietratelimit("log-low-rssi", 2)) {
                UserError.Log.d(TAG, "Low rssi device: " + bleScanResult.getBleDevice().getMacAddress() + " rssi: " + rssi);
            }
        }
    }
 
Example #20
Source File: ScanMeister.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
protected synchronized void onScanResult(ScanResult bleScanResult) {

        if (!wideSearch && address == null && name == null) {
            UserError.Log.d(TAG, "Address has been set to null, stopping scan.");
            stopScan("Address nulled");
            return;
        }

        try {
            for (ParcelUuid p : bleScanResult.getScanRecord().getServiceUuids()) {
                UserError.Log.d(TAG,"SERVICE: "+p.getUuid());
            }

        } catch (Exception e) {
            //
        }
        final int rssi = bleScanResult.getRssi();
        if (rssi > MINIMUM_RSSI) {
            //final String this_name = bleScanResult.getBleDevice().getName();
            final String this_address = bleScanResult.getBleDevice().getMacAddress();
            String this_name = "";
            if (name != null || customFilter != null) {
                this_name = bleScanResult.getBleDevice().getName();
            }
            final boolean matches = (customFilter != null)
                    || ((address != null && address.equalsIgnoreCase(this_address))
                    || (name != null && this_name != null && name.contains(this_name)));
            if (matches || JoH.quietratelimit("scanmeister-show-result", 2)) {
                UserError.Log.d(TAG, "Found a device: " + this_address + " " + this_name + " rssi: " + rssi + "  " + (matches ? "-> MATCH" : ""));
            }
            if (matches && stopOnFirstMatch) {
                stopScan("Got match");
                JoH.threadSleep(500);
                processCallBacks(this_address, SCAN_FOUND_CALLBACK, this_name, null);
                releaseWakeLock();
            }
            if (matches && !stopOnFirstMatch) {
                // TODO deposit good information in bundle - TODO: dry
                processCallBacks(this_address, SCAN_FOUND_CALLBACK, this_name, null);
            }

        } else {
            if (JoH.quietratelimit("log-low-rssi", 2)) {
                UserError.Log.d(TAG, "Low rssi device: " + bleScanResult.getBleDevice().getMacAddress() + " rssi: " + rssi);
            }
        }
    }
 
Example #21
Source File: ScanResultsAdapter.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
ScanResult getItemAtPosition(int childAdapterPosition) {
    return data.get(childAdapterPosition);
}
 
Example #22
Source File: ClientComponent.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
@Binds
abstract Function<RxBleInternalScanResult, ScanResult> provideScanResultMapper(InternalToExternalScanResultConverter mapper);
 
Example #23
Source File: ScanMeister.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
protected synchronized void onScanResult(ScanResult bleScanResult) {

        if (!wideSearch && address == null && name == null) {
            UserError.Log.d(TAG, "Address has been set to null, stopping scan.");
            stopScan("Address nulled");
            return;
        }

        try {
            for (ParcelUuid p : bleScanResult.getScanRecord().getServiceUuids()) {
                UserError.Log.d(TAG,"SERVICE: "+p.getUuid());
            }

        } catch (Exception e) {
            //
        }
        final int rssi = bleScanResult.getRssi();
        if (rssi > MINIMUM_RSSI) {
            //final String this_name = bleScanResult.getBleDevice().getName();
            final String this_address = bleScanResult.getBleDevice().getMacAddress();
            String this_name = "";
            if (name != null || customFilter != null) {
                this_name = bleScanResult.getBleDevice().getName();
            }
            final boolean matches = (customFilter != null)
                    || ((address != null && address.equalsIgnoreCase(this_address))
                    || (name != null && this_name != null && name.contains(this_name)));
            if (matches || JoH.quietratelimit("scanmeister-show-result", 2)) {
                UserError.Log.d(TAG, "Found a device: " + this_address + " " + this_name + " rssi: " + rssi + "  " + (matches ? "-> MATCH" : ""));
            }
            if (matches && stopOnFirstMatch) {
                stopScan("Got match");
                JoH.threadSleep(500);
                processCallBacks(this_address, SCAN_FOUND_CALLBACK);
                releaseWakeLock();
            }
            if (matches && !stopOnFirstMatch) {
                // TODO deposit good information in bundle - TODO: dry
                processCallBacks(this_address, SCAN_FOUND_CALLBACK, this_name, null);
            }

        } else {
            if (JoH.quietratelimit("log-low-rssi", 2)) {
                UserError.Log.d(TAG, "Low rssi device: " + bleScanResult.getBleDevice().getMacAddress() + " rssi: " + rssi);
            }
        }
    }
 
Example #24
Source File: ScanMeister.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
protected synchronized void onScanResult(ScanResult bleScanResult) {

        if (!wideSearch && address == null && name == null) {
            UserError.Log.d(TAG, "Address has been set to null, stopping scan.");
            stopScan("Address nulled");
            return;
        }

        try {
            for (ParcelUuid p : bleScanResult.getScanRecord().getServiceUuids()) {
                UserError.Log.d(TAG,"SERVICE: "+p.getUuid());
            }

        } catch (Exception e) {
            //
        }
        final int rssi = bleScanResult.getRssi();
        if (rssi > MINIMUM_RSSI) {
            //final String this_name = bleScanResult.getBleDevice().getName();
            final String this_address = bleScanResult.getBleDevice().getMacAddress();
            String this_name = "";
            if (name != null || customFilter != null) {
                this_name = bleScanResult.getBleDevice().getName();
            }
            final boolean matches = (customFilter != null)
                    || ((address != null && address.equalsIgnoreCase(this_address))
                    || (name != null && this_name != null && name.contains(this_name)));
            if (matches || JoH.quietratelimit("scanmeister-show-result", 2)) {
                UserError.Log.d(TAG, "Found a device: " + this_address + " " + this_name + " rssi: " + rssi + "  " + (matches ? "-> MATCH" : ""));
            }
            if (matches && stopOnFirstMatch) {
                stopScan("Got match");
                JoH.threadSleep(500);
                processCallBacks(this_address, SCAN_FOUND_CALLBACK, this_name, null);
                releaseWakeLock();
            }
            if (matches && !stopOnFirstMatch) {
                // TODO deposit good information in bundle - TODO: dry
                processCallBacks(this_address, SCAN_FOUND_CALLBACK, this_name, null);
            }

        } else {
            if (JoH.quietratelimit("log-low-rssi", 2)) {
                UserError.Log.d(TAG, "Low rssi device: " + bleScanResult.getBleDevice().getMacAddress() + " rssi: " + rssi);
            }
        }
    }
 
Example #25
Source File: BackgroundScannerImpl.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
private ScanResult convertScanResultToRxAndroidBLEModel(int callbackType, android.bluetooth.le.ScanResult result) {
    return internalToExternalScanResultConverter.apply(internalScanResultCreator.create(callbackType, result));
}
 
Example #26
Source File: BackgroundScannerImpl.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private static List<android.bluetooth.le.ScanResult> extractScanResults(@NonNull Intent intent) {
    return (List<android.bluetooth.le.ScanResult>) intent.getSerializableExtra(BluetoothLeScanner.EXTRA_LIST_SCAN_RESULT);
}
 
Example #27
Source File: RxBleClient.java    From RxAndroidBle with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an infinite observable emitting BLE scan results.
 * Scan is automatically started and stopped based on the Observable lifecycle.
 * Scan is started on subscribe and stopped on unsubscribe. You can safely subscribe multiple observers to this observable.
 * <p>
 * The library automatically handles Bluetooth adapter state changes but you are supposed to prompt the user
 * to enable it if it is disabled
 *
 * This function works on Android 4.3 in compatibility (emulated) mode.
 *
 * @param scanSettings Scan settings
 * @param scanFilters Filtering settings. ScanResult will be emitted if <i>any</i> of the passed scan filters will match.
 */
public abstract Observable<ScanResult> scanBleDevices(ScanSettings scanSettings, ScanFilter... scanFilters);