android 蓝牙 setscanmode,使用ScanSettings.SCAN_MODE_OPPORTUNISTIC“应用程序扫描得太频繁”...

我注意到三星S8,Android 7.0( 更新,这也发生在Android 7.0上:三星S7,Nexus 5x )的一个问题,告诉(testing之后)该应用程序扫描太频繁:

08-14 12:44:20.693 25329-25329/com.my.app D/BluetoothAdapter: startLeScan(): null 08-14 12:44:20.695 25329-25329/com.my.app D/BluetoothAdapter: STATE_ON 08-14 12:44:20.696 25329-25329/com.my.app D/BluetoothAdapter: STATE_ON 08-14 12:44:20.698 25329-25329/com.my.app D/BluetoothLeScanner: Start Scan 08-14 12:44:20.699 25329-25329/com.my.app D/BluetoothAdapter: STATE_ON 08-14 12:44:20.700 25329-25329/com.my.app D/BluetoothAdapter: STATE_ON 08-14 12:44:20.700 25329-25329/com.my.app D/BluetoothAdapter: STATE_ON 08-14 12:44:20.701 25329-25329/com.my.app D/BluetoothAdapter: STATE_ON 08-14 12:44:20.703 4079-4093/? D/BtGatt.GattService: registerClient() - UUID=dbaafee1-caf1-4482-9025-b712f000eeab 08-14 12:44:20.807 4079-4204/? D/BtGatt.GattService: onClientRegistered() - UUID=dbaafee1-caf1-4482-9025-b712f000eeab, clientIf=5, status=0 08-14 12:44:20.808 25329-25342/com.my.app D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=5 mClientIf=0 08-14 12:44:20.809 4079-7185/? D/BtGatt.GattService: start scan with filters 08-14 12:44:20.811 4079-7185/? D/BtGatt.GattService: getScanSettings 08-14 12:44:20.812 4079-7185/? D/BtGatt.GattService: Is it foreground application = true 08-14 12:44:20.812 4079-7185/? D/BtGatt.GattService: not a background application 08-14 12:44:20.817 4079-7185/? E/BtGatt.GattService: App 'com.my.app' is scanning too frequently

问题肯定在于那些6 STATE_ON调用结果,这是无证BLE行为变化的一部分,在DP4发行说明中首次提到:我们已经改变了从DP4开始的BLE扫描行为。 我们将阻止应用程序在30秒内启动和停止扫描超过5次。 对于长时间运行的扫描,我们将它们转换为伺机扫描。

即使设置了ScanSettings.setScanMode(ScanSettings.SCAN_MODE_OPPORTUNISTIC)我也不会在30秒内得到这6次扫描。

代码是:

List filters = new ArrayList<>(); ScanSettings scanSettings = new ScanSettings.Builder() .setScanMode(ScanSettings.SCAN_MODE_OPPORTUNISTIC) .build(); bluetoothAdapter.getBluetoothLeScanner().startScan(filters, scanSettings, recoderScanCallback); //events from the log happen before this log is printed Log.i("test", " started!"); return recoderScanCallback.scanResultObservable().map((ScanResult record) -> { //never gets here Log.i("test", " result!"); });

RecorderScanCallback源自ScanCallback 。 我们不能使用RxAndroidBle#rxBleClient.scanBleSettings (ScanSettings),因为我们的代码即将冻结,我们使用lib的1.1.0版本。

为什么ScanSettings.setScanMode不能改变search结果?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值