Android蓝牙低功耗 - 使用ScanFilters

时间:2015-03-24 15:24:58

标签: android filter bluetooth bluetooth-lowenergy

我目前正在开发用于蓝牙低功耗扫描的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中的app过滤器,它会给我一条错误消息,这可能会有所帮助。这是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 个答案:

答案 0 :(得分:1)

这个问题显然是Android 5.0中的一个错误。 使用较新版本的Android(使用5.0.2测试),错误已得到修复,问题不再发生。 非常感谢。

答案 1 :(得分:0)

这是评论/建议不是答案,因为在这里添加了很长的帖子。

克里斯,我没有看到蓝牙实施中的任何检查,其中有13个过滤器的限制,

遵循以下建议&gt;

1)为什么低于代码

  

while(扫描){

2)将您的scanResult回调作为匿名类添加到外部。

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

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

5)添加logcat(完整版),而不是为您的应用程序过滤掉一个。

6)为什么这个

  

的Thread.sleep(myScanTime);

使用新的Handler.postDelayed(new Runnable {void run(){}},scanTime);代替。

7)使scanTime更大,如1分钟,你使用更多的过滤器,将需要更多的时间来获得扫描结果的回调。

在这个答案中提到我的评论,我会回来并跟进。