Android 蓝牙低功耗 - 使用扫描过滤器

5
我目前正在为蓝牙低功耗扫描开发安卓应用。在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)

看起来有一个可用空间变量用于筛选器,它总是设置为15,无论添加了多少个筛选器。

onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=15

每添加一个筛选器,它就会减少一个,如果它降到小于3,就会触发NoSuchElementException异常。

2个回答

1
问题显然是安卓5.0中的一个bug。 在更新版本的安卓(已测试过5.0.2)中,该bug已经被修复,问题不再出现。 尽管如此,还是要感谢。

在回调函数中应用手动过滤器,伪代码如下:if (filterMap.contains(result.getAddress)){ ... 做一些事情 } - Chris

0

这是一条评论/建议,不是答案,由于帖子过长,我在此添加。

Chris,我没有看到蓝牙实现中的任何检查,它有13个过滤器的限制,

请按照以下建议操作 >

1)修改以下代码:

while (scanning) {

2)将您的scanResult回调添加为匿名类。

3)在onScanResult回调中打印扫描结果。

4)在onScanFailed回调中打印失败原因。

5)将logcat(complete)添加进来,而不是仅仅添加您应用程序的过滤器。

6)为什么要使用这个?

Thread.sleep(myScanTime);

使用新的Handler.postDelayed(new Runnable{void run(){}},scanTime);代替。
7) 将scanTime设置为更大的值,如1分钟,使用更多的过滤器将需要更长时间才能获得扫描结果的回调。
在此答案中提到我的评论,我会回来跟进。

非常感谢您的建议。我尝试了一下,但不幸的是错误仍然存在。Logcat没有打印任何内容,因为既没有调用onScanResult也没有调用onScanFailed,因为没有回调...似乎它甚至没有开始扫描。logcat只包含以下内容: BluetoothLeScanner﹕ onClientRegistered() - status=0 clientIf=6while语句与sleep或wait块是因为我需要每隔几秒钟重复扫描一次,持续很短的时间。但即使消除了这个问题,也没有帮助。看起来好像有太多的过滤器需要加载扫描,所以扫描需要花费太长时间... - Chris
什么是availableSpace? - AAnkit
我不确定它在哪里设置,但它在logcat输出中:例如onScanFilterParamsConfigured() - clientIf=6, status=0, action=0, availableSpace=8 - Chris
感谢您提供帮助。由于这是嵌入在一个较大的应用程序中,我必须先问我的老板,他周一之前不会在场...如果你还有兴趣并且他同意的话,当然可以。 - Chris
我不感兴趣查看你的代码。我只是想帮忙,如果你需要的话我很愿意提供帮助。 :) 祝编码愉快。 - AAnkit
显示剩余3条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接