Android 低功耗蓝牙 - 使用 ScanFilters
Android Bluetooth Low Energy - Using ScanFilters
我目前正在开发一个用于低功耗蓝牙扫描的 Android 应用程序。在 Android 5.0 中,引入了 ScanFilters 选项。它一般都能正常工作,但过滤器的数量似乎有限 (?)
如果我使用超过 13 个不同的过滤器,我将无法再找到任何 BLE 设备,并且我会收到应用程序已停止的通知,即使它在后台继续运行也没有找到任何东西。我没有收到警告或错误消息。如果我使用的过滤器少于 13 个,则一切正常。用于过滤的地址也不会导致问题。它归结为看起来的最大数量......
代码:
扫描在自己的线程中运行:
[...]
BluetoothLeScanner myScanner = myBluetoothAdapter.getBluetoothLeScanner();
ScanSettings settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
//The list for the filters
filters = new ArrayList<>();
//mac adresses of ble devices
String[] filterlist = {
"D4:B4:C8:7E:D1:35",
"C8:86:3A:91:0C:0C",
"FD:49:FD:36:04:B4",
"E9:91:4A:42:AC:3B",
//... some 20 more addresses
};
//adding the mac adresses to the filters list
for (int i=0; i< filterlist.length ; i++) {
ScanFilter filter = new ScanFilter.Builder().setDeviceAddress(filterlist[i]).build();
filters.add(filter);
Log.v("Filter: "," "+ filters.get(i).getDeviceAddress());
}
[...]
while (scanning) {
final ScanCallback callback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
Log.v("Callback","in the callback");
}
@Override
public void onScanFailed(int errorCode) {
super.onScanFailed(errorCode);
Log.v("ScanTask", "Some error occurred");
});
[...]
//starting the scan with the filters
myScanner.startScan(filters, settings, callback);
//creating some delay and then end the scan
Thread.sleep(myScanTime);
myScanner.stopScan(callback);
[...]
}
代码内部似乎没有问题。但是为什么过滤器的最大数量有限制呢?有人可以将我推向正确的方向或知道解决方法吗?
更新:
删除 Logcat 中的应用过滤器,它会给我一条错误消息,这可能会有所帮助。这是 Logcat:
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ EC:2F:08:1E:99:DC
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ F0:5E:4A:36:D5:4F
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ E1:24:88:12:B7:20
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ D1:F7:F3:73:00:43
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ D4:B6:92:2B:7C:EB
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ DE:6D:4A:07:DB:36
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ 00:07:80:1F:CD:19
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ 00:07:80:1F:C3:3B
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ 00:07:80:1F:C6:F2
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ 00:07:80:1F:C2:DF
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ 00:07:80:1F:C6:EA
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ 00:07:80:1F:C7:7C
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ 00:07:80:1F:C2:D1
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ 00:07:80:1F:C7:78
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ 00:07:80:1F:C7:74
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ 00:07:80:1F:C2:B8
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ 00:07:80:1F:C3:3A
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ 00:07:80:1F:CD:2F
03-25 09:35:33.899 18922-19072/? D/BtGatt.GattService﹕ registerClient() - UUID=9f64337e-6700-4c26-a1f1-64ddc5b874c1
03-25 09:35:33.909 18922-18940/? D/BtGatt.GattService﹕ onClientRegistered() - UUID=9f64337e-6700-4c26-a1f1-64ddc5b874c1, clientIf=6
03-25 09:35:33.919 18166-18180/com.example.install.bluetooth_app D/BluetoothLeScanner﹕ onClientRegistered() - status=0 clientIf=6
03-25 09:35:33.919 18922-18931/? D/BtGatt.GattService﹕ start scan with filters
03-25 09:35:33.929 18922-18944/? D/BtGatt.ScanManager﹕ handling starting scan
03-25 09:35:33.929 18922-18944/? D/BluetoothAdapterService﹕ getAdapterService() - returning com.android.bluetooth.btservice.AdapterService@90e686a
03-25 09:35:33.929 18166-19305/com.example.install.bluetooth_app V/ScanTask﹕ Scan is started
03-25 09:35:33.929 18166-19305/com.example.install.bluetooth_app V/ScanTask﹕ Filters: 18
03-25 09:35:33.929 18166-19305/com.example.install.bluetooth_app V/ScanTask﹕ ScanTime: 5000
03-25 09:35:33.929 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.939 18922-19015/? D/bt_upio﹕ proc btwrite assertion
03-25 09:35:33.949 18922-18940/? D/BtGatt.GattService﹕ onScanFilterEnableDisabled() - clientIf=6, status=0, action=1
03-25 09:35:33.949 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.949 18922-18944/? D/BtGatt.ScanManager﹕ allow scan with filters
03-25 09:35:33.949 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 3 for clientIf= 6
03-25 09:35:33.949 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:33.949 18922-18944/? D/BtGatt.ScanManager﹕ add address EC:2F:08:1E:99:DC
03-25 09:35:33.949 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.949 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.949 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=47
03-25 09:35:33.949 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.949 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.949 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.949 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=15
03-25 09:35:33.949 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.949 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 4 for clientIf= 6
03-25 09:35:33.949 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:33.949 18922-18944/? D/BtGatt.ScanManager﹕ add address F0:5E:4A:36:D5:4F
03-25 09:35:33.959 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.959 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.959 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=46
03-25 09:35:33.959 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.959 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.959 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.959 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=14
03-25 09:35:33.959 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.959 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 5 for clientIf= 6
03-25 09:35:33.959 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:33.959 18922-18944/? D/BtGatt.ScanManager﹕ add address E1:24:88:12:B7:20
03-25 09:35:33.959 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.959 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.959 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=45
03-25 09:35:33.959 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.969 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.969 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.969 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=13
03-25 09:35:33.969 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.969 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 6 for clientIf= 6
03-25 09:35:33.969 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:33.969 18922-18944/? D/BtGatt.ScanManager﹕ add address D1:F7:F3:73:00:43
03-25 09:35:33.969 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.969 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.969 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=44
03-25 09:35:33.969 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.969 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.969 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.969 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=12
03-25 09:35:33.969 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.979 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 7 for clientIf= 6
03-25 09:35:33.979 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:33.979 18922-18944/? D/BtGatt.ScanManager﹕ add address D4:B6:92:2B:7C:EB
03-25 09:35:33.979 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.979 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.979 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=43
03-25 09:35:33.979 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.979 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.979 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.979 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=11
03-25 09:35:33.979 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.979 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 8 for clientIf= 6
03-25 09:35:33.979 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:33.979 18922-18944/? D/BtGatt.ScanManager﹕ add address DE:6D:4A:07:DB:36
03-25 09:35:33.979 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.979 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.979 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=42
03-25 09:35:33.979 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.989 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.989 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.989 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=10
03-25 09:35:33.989 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.989 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 9 for clientIf= 6
03-25 09:35:33.989 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:33.989 18922-18944/? D/BtGatt.ScanManager﹕ add address 00:07:80:1F:CD:19
03-25 09:35:33.989 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.989 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.989 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=41
03-25 09:35:33.989 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.989 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.989 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.989 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=9
03-25 09:35:33.989 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.989 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 10 for clientIf= 6
03-25 09:35:33.989 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:33.989 18922-18944/? D/BtGatt.ScanManager﹕ add address 00:07:80:1F:C3:3B
03-25 09:35:33.989 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.989 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.999 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=40
03-25 09:35:33.999 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.999 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.999 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.999 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=8
03-25 09:35:33.999 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.999 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 11 for clientIf= 6
03-25 09:35:33.999 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:33.999 18922-18944/? D/BtGatt.ScanManager﹕ add address 00:07:80:1F:C6:F2
03-25 09:35:33.999 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.999 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:34.009 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=39
03-25 09:35:34.009 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:34.009 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:34.009 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:34.009 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=7
03-25 09:35:34.009 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:34.009 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 12 for clientIf= 6
03-25 09:35:34.009 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:34.009 18922-18944/? D/BtGatt.ScanManager﹕ add address 00:07:80:1F:C2:DF
03-25 09:35:34.009 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:34.009 1158-1158/? D/StatusBar.NetworkController﹕ onSignalStrengthsChanged signalStrength=SignalStrength: 12 99 -120 -160 -120 -1 -1 99 2147483647 2147483647 2147483647 -1 2147483647 0x4 gsm|lte level=4
03-25 09:35:34.009 1158-1158/? D/StatusBar.NetworkController﹕ updateTelephonySignalStrength: hasService=true ss=SignalStrength: 12 99 -120 -160 -120 -1 -1 99 2147483647 2147483647 2147483647 -1 2147483647 0x4 gsm|lte
03-25 09:35:34.009 1158-1158/? D/StatusBar.NetworkController﹕ updateTelephonySignalStrength: iconLevel=4
03-25 09:35:34.009 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:34.009 1158-1158/? D/StatusBar.NetworkController﹕ updateTelephonySignalStrength, No signal level. mPhoneSignalIconId = com.android.systemui:drawable/stat_sys_signal_4_auto_rotate mDataSignalIconId = com.android.systemui:drawable/stat_sys_signal_4_auto_rotate mQSPhoneSignalIconId = com.android.systemui:drawable/ic_qs_signal_4 mContentDescriptionPhoneSignal = Volle Signalstärke
03-25 09:35:34.009 1158-1158/? D/StatusBar.NetworkController﹕ refreshViews connected={ wifi } level=4 combinedSignalIconId=0x7f020495/com.android.systemui:drawable/stat_sys_wifi_signal_4 mobileLabel=3 AT wifiLabel="W_ISPACE01"xxxxXXXXxxxxXXXX emergencyOnly=false combinedLabel="W_ISPACE01"xxxxXXXXxxxxXXXX mAirplaneMode=false mDataActivity=0 mPhoneSignalIconId=0x7f020440/com.android.systemui:drawable/stat_sys_signal_4_auto_rotate mQSPhoneSignalIconId=0x7f020115/com.android.systemui:drawable/ic_qs_signal_4 mDataDirectionIconId=0x0/(null) mDataSignalIconId=0x7f020440/com.android.systemui:drawable/stat_sys_signal_4_auto_rotate mDataTypeIconId=0x7f0202c9/com.android.systemui:drawable/stat_sys_data_connected_h mQSDataTypeIconId=0x7f02011f/com.android.systemui:drawable/ic_qs_signal_h mNoSimIconId=0x0/(null) mWifiIconId=0x7f020495/com.android.systemui:drawable/stat_sys_wifi_signal_4 mQSWifiIconId=0x7f02012b/com.android.systemui:drawable/ic_qs_wifi_4 mWifiActivityIconId=0x7f020464/com.android.systemui:drawable/stat_sys_signal_in mBluetoothTetherIconId=0x1080907/android:drawable/stat_sys_tether_bluetooth
03-25 09:35:34.009 1158-1158/? D/StatusBar.NetworkController﹕ refreshSignalCluster - setNWBoosterIndicators(false)
03-25 09:35:34.009 1158-1158/? D/StatusBar.NetworkController﹕ applyOpen
03-25 09:35:34.009 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=38
03-25 09:35:34.009 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:34.009 1158-1158/? D/StatusBar.NetworkController﹕ refreshSignalCluster - setNWBoosterIndicators(false)
03-25 09:35:34.009 1158-1158/? D/StatusBar.NetworkController﹕ applyOpen
03-25 09:35:34.009 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:34.009 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:34.009 1158-1158/? D/StatusBar.NetworkController﹕ refreshSignalCluster - setNWBoosterIndicators(false)
03-25 09:35:34.009 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=6
03-25 09:35:34.009 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:34.009 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 13 for clientIf= 6
03-25 09:35:34.009 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:34.009 18922-18944/? D/BtGatt.ScanManager﹕ add address 00:07:80:1F:C6:EA
03-25 09:35:34.009 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:34.009 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:34.009 1158-1158/? D/StatusBar.NetworkController﹕ applyOpen
03-25 09:35:34.019 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=37
03-25 09:35:34.019 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:34.019 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:34.019 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:34.019 1158-1158/? D/StatusBar.NetworkController﹕ refreshSignalCluster - setNWBoosterIndicators(false)
03-25 09:35:34.019 1158-1158/? D/StatusBar.NetworkController﹕ applyOpen
03-25 09:35:34.019 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=5
03-25 09:35:34.019 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:34.019 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 14 for clientIf= 6
03-25 09:35:34.019 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:34.019 18922-18944/? D/BtGatt.ScanManager﹕ add address 00:07:80:1F:C7:7C
03-25 09:35:34.019 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:34.019 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:34.019 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=36
03-25 09:35:34.019 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:34.019 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:34.019 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:34.019 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=4
03-25 09:35:34.019 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:34.019 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 15 for clientIf= 6
03-25 09:35:34.019 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:34.019 18922-18944/? D/BtGatt.ScanManager﹕ add address 00:07:80:1F:C2:D1
03-25 09:35:34.019 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:34.019 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:34.029 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=35
03-25 09:35:34.029 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:34.029 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:34.029 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:34.029 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=3
03-25 09:35:34.029 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:34.029 18922-18944/? E/AndroidRuntime﹕ FATAL EXCEPTION: BluetoothScanManager
Process: com.android.bluetooth, PID: 18922
java.util.NoSuchElementException
at java.util.ArrayDeque.removeFirst(ArrayDeque.java:248)
at java.util.ArrayDeque.pop(ArrayDeque.java:483)
at com.android.bluetooth.gatt.ScanManager$ScanNative.configureScanFilters(ScanManager.java:738)
at com.android.bluetooth.gatt.ScanManager$ScanNative.startRegularScan(ScanManager.java:529)
at com.android.bluetooth.gatt.ScanManager$ClientHandler.handleStartScan(ScanManager.java:212)
at com.android.bluetooth.gatt.ScanManager$ClientHandler.handleMessage(ScanManager.java:179)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.os.HandlerThread.run(HandlerThread.java:61)
似乎有一个过滤器可用的变量 Space,它始终设置为 15,与添加的过滤器数量无关(?)
onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=15
每添加一个过滤器它就会减少 1,如果低于 3,就会触发 NoSuchElementException。
这 comment/Suggestion 不是答案,因为 post 在此处添加它很长。
Chris,我没有在蓝牙实现中看到任何检查,它有 13 个过滤器的限制,
遵循以下建议 >
1) 为什么下面的代码
while (scanning) {
2) 在外部添加您的 scanResult 回调作为匿名 class。
3) 在 ScanResult 回调中打印扫描结果。
4) 在 onScanFailed 回调中打印失败原因。
5) 添加 logcat(完成)而不是您为您的应用筛选的一个。
6) 为什么这样
Thread.sleep(myScanTime);
使用新的Handler.postDelayed(新的Runnable{void 运行(){}},scanTime);相反。
7) 将scanTime设置为更大的值,例如1分钟,使用的过滤器越多,获取扫描结果的回调将花费更多时间。
评论提到我这个答案,我会回来跟进。
这个问题显然是 Android 5.0 中的错误。
使用较新版本的 Android(使用 5.0.2 测试)错误已修复,问题不再发生。
谢谢none少
我目前正在开发一个用于低功耗蓝牙扫描的 Android 应用程序。在 Android 5.0 中,引入了 ScanFilters 选项。它一般都能正常工作,但过滤器的数量似乎有限 (?)
如果我使用超过 13 个不同的过滤器,我将无法再找到任何 BLE 设备,并且我会收到应用程序已停止的通知,即使它在后台继续运行也没有找到任何东西。我没有收到警告或错误消息。如果我使用的过滤器少于 13 个,则一切正常。用于过滤的地址也不会导致问题。它归结为看起来的最大数量......
代码: 扫描在自己的线程中运行:
[...]
BluetoothLeScanner myScanner = myBluetoothAdapter.getBluetoothLeScanner();
ScanSettings settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
//The list for the filters
filters = new ArrayList<>();
//mac adresses of ble devices
String[] filterlist = {
"D4:B4:C8:7E:D1:35",
"C8:86:3A:91:0C:0C",
"FD:49:FD:36:04:B4",
"E9:91:4A:42:AC:3B",
//... some 20 more addresses
};
//adding the mac adresses to the filters list
for (int i=0; i< filterlist.length ; i++) {
ScanFilter filter = new ScanFilter.Builder().setDeviceAddress(filterlist[i]).build();
filters.add(filter);
Log.v("Filter: "," "+ filters.get(i).getDeviceAddress());
}
[...]
while (scanning) {
final ScanCallback callback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
Log.v("Callback","in the callback");
}
@Override
public void onScanFailed(int errorCode) {
super.onScanFailed(errorCode);
Log.v("ScanTask", "Some error occurred");
});
[...]
//starting the scan with the filters
myScanner.startScan(filters, settings, callback);
//creating some delay and then end the scan
Thread.sleep(myScanTime);
myScanner.stopScan(callback);
[...]
}
代码内部似乎没有问题。但是为什么过滤器的最大数量有限制呢?有人可以将我推向正确的方向或知道解决方法吗?
更新: 删除 Logcat 中的应用过滤器,它会给我一条错误消息,这可能会有所帮助。这是 Logcat:
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ EC:2F:08:1E:99:DC
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ F0:5E:4A:36:D5:4F
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ E1:24:88:12:B7:20
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ D1:F7:F3:73:00:43
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ D4:B6:92:2B:7C:EB
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ DE:6D:4A:07:DB:36
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ 00:07:80:1F:CD:19
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ 00:07:80:1F:C3:3B
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ 00:07:80:1F:C6:F2
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ 00:07:80:1F:C2:DF
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ 00:07:80:1F:C6:EA
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ 00:07:80:1F:C7:7C
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ 00:07:80:1F:C2:D1
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ 00:07:80:1F:C7:78
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ 00:07:80:1F:C7:74
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ 00:07:80:1F:C2:B8
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ 00:07:80:1F:C3:3A
03-25 09:35:32.889 18166-19305/com.example.install.bluetooth_app V/Filter:﹕ 00:07:80:1F:CD:2F
03-25 09:35:33.899 18922-19072/? D/BtGatt.GattService﹕ registerClient() - UUID=9f64337e-6700-4c26-a1f1-64ddc5b874c1
03-25 09:35:33.909 18922-18940/? D/BtGatt.GattService﹕ onClientRegistered() - UUID=9f64337e-6700-4c26-a1f1-64ddc5b874c1, clientIf=6
03-25 09:35:33.919 18166-18180/com.example.install.bluetooth_app D/BluetoothLeScanner﹕ onClientRegistered() - status=0 clientIf=6
03-25 09:35:33.919 18922-18931/? D/BtGatt.GattService﹕ start scan with filters
03-25 09:35:33.929 18922-18944/? D/BtGatt.ScanManager﹕ handling starting scan
03-25 09:35:33.929 18922-18944/? D/BluetoothAdapterService﹕ getAdapterService() - returning com.android.bluetooth.btservice.AdapterService@90e686a
03-25 09:35:33.929 18166-19305/com.example.install.bluetooth_app V/ScanTask﹕ Scan is started
03-25 09:35:33.929 18166-19305/com.example.install.bluetooth_app V/ScanTask﹕ Filters: 18
03-25 09:35:33.929 18166-19305/com.example.install.bluetooth_app V/ScanTask﹕ ScanTime: 5000
03-25 09:35:33.929 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.939 18922-19015/? D/bt_upio﹕ proc btwrite assertion
03-25 09:35:33.949 18922-18940/? D/BtGatt.GattService﹕ onScanFilterEnableDisabled() - clientIf=6, status=0, action=1
03-25 09:35:33.949 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.949 18922-18944/? D/BtGatt.ScanManager﹕ allow scan with filters
03-25 09:35:33.949 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 3 for clientIf= 6
03-25 09:35:33.949 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:33.949 18922-18944/? D/BtGatt.ScanManager﹕ add address EC:2F:08:1E:99:DC
03-25 09:35:33.949 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.949 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.949 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=47
03-25 09:35:33.949 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.949 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.949 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.949 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=15
03-25 09:35:33.949 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.949 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 4 for clientIf= 6
03-25 09:35:33.949 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:33.949 18922-18944/? D/BtGatt.ScanManager﹕ add address F0:5E:4A:36:D5:4F
03-25 09:35:33.959 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.959 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.959 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=46
03-25 09:35:33.959 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.959 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.959 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.959 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=14
03-25 09:35:33.959 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.959 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 5 for clientIf= 6
03-25 09:35:33.959 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:33.959 18922-18944/? D/BtGatt.ScanManager﹕ add address E1:24:88:12:B7:20
03-25 09:35:33.959 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.959 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.959 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=45
03-25 09:35:33.959 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.969 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.969 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.969 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=13
03-25 09:35:33.969 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.969 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 6 for clientIf= 6
03-25 09:35:33.969 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:33.969 18922-18944/? D/BtGatt.ScanManager﹕ add address D1:F7:F3:73:00:43
03-25 09:35:33.969 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.969 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.969 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=44
03-25 09:35:33.969 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.969 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.969 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.969 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=12
03-25 09:35:33.969 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.979 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 7 for clientIf= 6
03-25 09:35:33.979 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:33.979 18922-18944/? D/BtGatt.ScanManager﹕ add address D4:B6:92:2B:7C:EB
03-25 09:35:33.979 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.979 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.979 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=43
03-25 09:35:33.979 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.979 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.979 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.979 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=11
03-25 09:35:33.979 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.979 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 8 for clientIf= 6
03-25 09:35:33.979 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:33.979 18922-18944/? D/BtGatt.ScanManager﹕ add address DE:6D:4A:07:DB:36
03-25 09:35:33.979 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.979 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.979 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=42
03-25 09:35:33.979 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.989 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.989 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.989 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=10
03-25 09:35:33.989 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.989 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 9 for clientIf= 6
03-25 09:35:33.989 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:33.989 18922-18944/? D/BtGatt.ScanManager﹕ add address 00:07:80:1F:CD:19
03-25 09:35:33.989 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.989 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.989 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=41
03-25 09:35:33.989 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.989 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.989 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.989 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=9
03-25 09:35:33.989 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.989 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 10 for clientIf= 6
03-25 09:35:33.989 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:33.989 18922-18944/? D/BtGatt.ScanManager﹕ add address 00:07:80:1F:C3:3B
03-25 09:35:33.989 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.989 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.999 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=40
03-25 09:35:33.999 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.999 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.999 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:33.999 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=8
03-25 09:35:33.999 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:33.999 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 11 for clientIf= 6
03-25 09:35:33.999 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:33.999 18922-18944/? D/BtGatt.ScanManager﹕ add address 00:07:80:1F:C6:F2
03-25 09:35:33.999 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:33.999 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:34.009 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=39
03-25 09:35:34.009 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:34.009 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:34.009 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:34.009 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=7
03-25 09:35:34.009 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:34.009 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 12 for clientIf= 6
03-25 09:35:34.009 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:34.009 18922-18944/? D/BtGatt.ScanManager﹕ add address 00:07:80:1F:C2:DF
03-25 09:35:34.009 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:34.009 1158-1158/? D/StatusBar.NetworkController﹕ onSignalStrengthsChanged signalStrength=SignalStrength: 12 99 -120 -160 -120 -1 -1 99 2147483647 2147483647 2147483647 -1 2147483647 0x4 gsm|lte level=4
03-25 09:35:34.009 1158-1158/? D/StatusBar.NetworkController﹕ updateTelephonySignalStrength: hasService=true ss=SignalStrength: 12 99 -120 -160 -120 -1 -1 99 2147483647 2147483647 2147483647 -1 2147483647 0x4 gsm|lte
03-25 09:35:34.009 1158-1158/? D/StatusBar.NetworkController﹕ updateTelephonySignalStrength: iconLevel=4
03-25 09:35:34.009 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:34.009 1158-1158/? D/StatusBar.NetworkController﹕ updateTelephonySignalStrength, No signal level. mPhoneSignalIconId = com.android.systemui:drawable/stat_sys_signal_4_auto_rotate mDataSignalIconId = com.android.systemui:drawable/stat_sys_signal_4_auto_rotate mQSPhoneSignalIconId = com.android.systemui:drawable/ic_qs_signal_4 mContentDescriptionPhoneSignal = Volle Signalstärke
03-25 09:35:34.009 1158-1158/? D/StatusBar.NetworkController﹕ refreshViews connected={ wifi } level=4 combinedSignalIconId=0x7f020495/com.android.systemui:drawable/stat_sys_wifi_signal_4 mobileLabel=3 AT wifiLabel="W_ISPACE01"xxxxXXXXxxxxXXXX emergencyOnly=false combinedLabel="W_ISPACE01"xxxxXXXXxxxxXXXX mAirplaneMode=false mDataActivity=0 mPhoneSignalIconId=0x7f020440/com.android.systemui:drawable/stat_sys_signal_4_auto_rotate mQSPhoneSignalIconId=0x7f020115/com.android.systemui:drawable/ic_qs_signal_4 mDataDirectionIconId=0x0/(null) mDataSignalIconId=0x7f020440/com.android.systemui:drawable/stat_sys_signal_4_auto_rotate mDataTypeIconId=0x7f0202c9/com.android.systemui:drawable/stat_sys_data_connected_h mQSDataTypeIconId=0x7f02011f/com.android.systemui:drawable/ic_qs_signal_h mNoSimIconId=0x0/(null) mWifiIconId=0x7f020495/com.android.systemui:drawable/stat_sys_wifi_signal_4 mQSWifiIconId=0x7f02012b/com.android.systemui:drawable/ic_qs_wifi_4 mWifiActivityIconId=0x7f020464/com.android.systemui:drawable/stat_sys_signal_in mBluetoothTetherIconId=0x1080907/android:drawable/stat_sys_tether_bluetooth
03-25 09:35:34.009 1158-1158/? D/StatusBar.NetworkController﹕ refreshSignalCluster - setNWBoosterIndicators(false)
03-25 09:35:34.009 1158-1158/? D/StatusBar.NetworkController﹕ applyOpen
03-25 09:35:34.009 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=38
03-25 09:35:34.009 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:34.009 1158-1158/? D/StatusBar.NetworkController﹕ refreshSignalCluster - setNWBoosterIndicators(false)
03-25 09:35:34.009 1158-1158/? D/StatusBar.NetworkController﹕ applyOpen
03-25 09:35:34.009 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:34.009 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:34.009 1158-1158/? D/StatusBar.NetworkController﹕ refreshSignalCluster - setNWBoosterIndicators(false)
03-25 09:35:34.009 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=6
03-25 09:35:34.009 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:34.009 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 13 for clientIf= 6
03-25 09:35:34.009 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:34.009 18922-18944/? D/BtGatt.ScanManager﹕ add address 00:07:80:1F:C6:EA
03-25 09:35:34.009 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:34.009 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:34.009 1158-1158/? D/StatusBar.NetworkController﹕ applyOpen
03-25 09:35:34.019 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=37
03-25 09:35:34.019 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:34.019 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:34.019 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:34.019 1158-1158/? D/StatusBar.NetworkController﹕ refreshSignalCluster - setNWBoosterIndicators(false)
03-25 09:35:34.019 1158-1158/? D/StatusBar.NetworkController﹕ applyOpen
03-25 09:35:34.019 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=5
03-25 09:35:34.019 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:34.019 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 14 for clientIf= 6
03-25 09:35:34.019 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:34.019 18922-18944/? D/BtGatt.ScanManager﹕ add address 00:07:80:1F:C7:7C
03-25 09:35:34.019 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:34.019 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:34.019 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=36
03-25 09:35:34.019 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:34.019 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:34.019 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:34.019 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=4
03-25 09:35:34.019 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:34.019 18922-18944/? D/BtGatt.ScanManager﹕ set filter index= 15 for clientIf= 6
03-25 09:35:34.019 18922-18944/? D/BtGatt.ScanManager﹕ addFilterToController: 0
03-25 09:35:34.019 18922-18944/? D/BtGatt.ScanManager﹕ add address 00:07:80:1F:C2:D1
03-25 09:35:34.019 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:34.019 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:34.029 18922-18940/? D/BtGatt.GattService﹕ onScanFilterConfig() - clientIf=6, action = 0 status = 0, filterType=0, availableSpace=35
03-25 09:35:34.029 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:34.029 18922-19015/? D/bt_vendor﹕ op for 7
03-25 09:35:34.029 18922-19015/? D/bt_upio﹕ BT_WAKE is asserted already
03-25 09:35:34.029 18922-18940/? D/BtGatt.GattService﹕ onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=3
03-25 09:35:34.029 18922-18940/? D/BtGatt.ScanManager﹕ callback done for clientIf - 6 status - 0
03-25 09:35:34.029 18922-18944/? E/AndroidRuntime﹕ FATAL EXCEPTION: BluetoothScanManager
Process: com.android.bluetooth, PID: 18922
java.util.NoSuchElementException
at java.util.ArrayDeque.removeFirst(ArrayDeque.java:248)
at java.util.ArrayDeque.pop(ArrayDeque.java:483)
at com.android.bluetooth.gatt.ScanManager$ScanNative.configureScanFilters(ScanManager.java:738)
at com.android.bluetooth.gatt.ScanManager$ScanNative.startRegularScan(ScanManager.java:529)
at com.android.bluetooth.gatt.ScanManager$ClientHandler.handleStartScan(ScanManager.java:212)
at com.android.bluetooth.gatt.ScanManager$ClientHandler.handleMessage(ScanManager.java:179)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.os.HandlerThread.run(HandlerThread.java:61)
似乎有一个过滤器可用的变量 Space,它始终设置为 15,与添加的过滤器数量无关(?)
onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=15
每添加一个过滤器它就会减少 1,如果低于 3,就会触发 NoSuchElementException。
这 comment/Suggestion 不是答案,因为 post 在此处添加它很长。
Chris,我没有在蓝牙实现中看到任何检查,它有 13 个过滤器的限制,
遵循以下建议 >
1) 为什么下面的代码
while (scanning) {
2) 在外部添加您的 scanResult 回调作为匿名 class。
3) 在 ScanResult 回调中打印扫描结果。
4) 在 onScanFailed 回调中打印失败原因。
5) 添加 logcat(完成)而不是您为您的应用筛选的一个。
6) 为什么这样
Thread.sleep(myScanTime);
使用新的Handler.postDelayed(新的Runnable{void 运行(){}},scanTime);相反。
7) 将scanTime设置为更大的值,例如1分钟,使用的过滤器越多,获取扫描结果的回调将花费更多时间。
评论提到我这个答案,我会回来跟进。
这个问题显然是 Android 5.0 中的错误。 使用较新版本的 Android(使用 5.0.2 测试)错误已修复,问题不再发生。 谢谢none少