protected virtual void StartNewScanner(ScanConfig config) { this.newCallback = new LollipopScanCallback(args => this.Scanned?.Invoke(this, args)); var scanMode = this.ToNative(config.ScanType); var filterBuilderList = new List <ScanFilter>(); if (config.ServiceUuids != null && config.ServiceUuids.Count > 0) { foreach (var uuid in config.ServiceUuids) { var filterBuilder = new ScanFilter.Builder(); filterBuilder.SetServiceUuid(uuid.ToParcelUuid()); filterBuilderList.Add(filterBuilder.Build()); } } else { var filterBuilder = new ScanFilter.Builder(); filterBuilderList.Add(filterBuilder.Build()); } //new ScanFilter.Builder().SetDeviceAddress().Set this.manager.Adapter.BluetoothLeScanner.StartScan( filterBuilderList, new ScanSettings .Builder() .SetScanMode(scanMode) .Build(), this.newCallback ); }
protected virtual IObservable <ScanResult> NewScan(ScanConfig config) => Observable.Create <ScanResult>(ob => { var cb = new LollipopScanCallback((native, rssi, sr) => { var scanResult = this.ToScanResult(native, rssi, new AdvertisementData(sr)); ob.OnNext(scanResult); }); var scanMode = this.ToNative(config.ScanType); var scanFilters = new List <ScanFilter>(); if (config.ServiceUuids != null && config.ServiceUuids.Count > 0) { foreach (var guid in config.ServiceUuids) { var uuid = guid.ToParcelUuid(); scanFilters.Add(new ScanFilter.Builder() .SetServiceUuid(uuid) .Build() ); } } this.manager.Adapter.BluetoothLeScanner.StartScan( scanFilters, new ScanSettings .Builder() .SetScanMode(scanMode) .Build(), cb ); return(() => this.manager.Adapter.BluetoothLeScanner?.StopScan(cb)); });
protected virtual IObservable <ScanResult> NewScan(ScanConfig config) => Observable.Create <ScanResult>(ob => { this.callbacks = new LollipopScanCallback((native, rssi, sr) => { var scanResult = this.ToScanResult(native, rssi, new AdvertisementData(sr)); ob.OnNext(scanResult); }); var builder = new ScanSettings.Builder(); var scanMode = this.ToNative(config.ScanType); builder.SetScanMode(scanMode); if (CrossBleAdapter.AndroidConfiguration.AdvancedScannerSettings) { if (config.MatchMode != null) { builder.SetMatchMode(this.ToNative(config.MatchMode.Value)); } if (config.NumOfMatches != null) { builder.SetNumOfMatches((int)this.ToNative(config.NumOfMatches.Value)); } } var scanFilters = new List <ScanFilter>(); if (config.ServiceUuids != null && config.ServiceUuids.Count > 0) { foreach (var guid in config.ServiceUuids) { var uuid = guid.ToParcelUuid(); scanFilters.Add(new ScanFilter.Builder() .SetServiceUuid(uuid) .Build() ); } } if (config.AndroidUseScanBatching && this.manager.Adapter.IsOffloadedScanBatchingSupported) { builder.SetReportDelay(100); } this.manager.Adapter.BluetoothLeScanner.StartScan( scanFilters, builder.Build(), this.callbacks ); return(() => this.manager.Adapter.BluetoothLeScanner?.StopScan(this.callbacks)); });
public void StopScan() { if (this.callbacks != null) { this.manager.Adapter.BluetoothLeScanner?.StopScan(this.callbacks); this.callbacks = null; } if (this.oldCallbacks != null) { this.manager.Adapter.StopLeScan(this.oldCallbacks); this.oldCallbacks = null; } }
public void StopScan() { if (this.callbacks != null) { this.manager.Adapter.BluetoothLeScanner?.StopScan(this.callbacks); this.callbacks = null; } if (this.oldCallbacks != null) { #pragma warning disable CS0618 // Type or member is obsolete this.manager.Adapter.StopLeScan(this.oldCallbacks); #pragma warning restore CS0618 // Type or member is obsolete this.oldCallbacks = null; } }
protected virtual void StartNewScanner(ScanConfig config) { this.newCallback = new LollipopScanCallback(args => this.Scanned?.Invoke(this, args)); var scanMode = this.ToNative(config.ScanType); var filterBuilder = new ScanFilter.Builder(); if (config.ServiceUuid != null) { filterBuilder.SetServiceUuid(config.ServiceUuid.Value.ToParcelUuid()); } //new ScanFilter.Builder().SetDeviceAddress().Set this.manager.Adapter.BluetoothLeScanner.StartScan( new [] { filterBuilder.Build() }, new ScanSettings .Builder() .SetScanMode(scanMode) .Build(), this.newCallback ); }