com.polidea.rxandroidble2.scan.BackgroundScanner Java Examples

The following examples show how to use com.polidea.rxandroidble2.scan.BackgroundScanner. 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: 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 #2
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 #3
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 #4
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 #5
Source File: RxBleClientImpl.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
@Override
public BackgroundScanner getBackgroundScanner() {
    return backgroundScanner;
}
 
Example #6
Source File: ClientComponent.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
@Binds
abstract BackgroundScanner bindBackgroundScanner(BackgroundScannerImpl backgroundScannerImpl);
 
Example #7
Source File: RxBleClientMock.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
@Override
public BackgroundScanner getBackgroundScanner() {
    throw new UnsupportedOperationException("Background scanning API is not supported by the mock.");
}
 
Example #8
Source File: RxBleClient.java    From RxAndroidBle with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a background scanner instance that can be used to handle background scans, even if your process is stopped.
 */
public abstract BackgroundScanner getBackgroundScanner();