我正在开发一款应用程序,可以在其中查找和配置BLE设备。我使用标准的Android BLE API,但最近我遇到了一些奇怪的问题。Android停止查找BLE设备:onClientRegistered() - status = 133 clientIf = 0
当我打开我的应用程序时,BLE扫描正常。
mBluetoothAdapter.startLeScan(mLeScanCallback); // for Kitkat and below
和
mBluetoothAdapter.getBluetoothLeScanner().startScan(mScanCallback); // for Lollipop and above
在我收到以下消息logcat的(我想这是很重要的这个问题):
D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
在我的应用我我使用扫描也可以读取我的BLE设备的某些特性(例如电池状态)。我连接到一个设备,使用以下单独的片段读取此特征:
mBluetoothManager = (BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = mBluetoothManager.getAdapter();
mBluetoothDevice = mBluetoothAdapter.getRemoteDevice(mMacAddress);
mBluetoothGatt = mBluetoothDevice.connectGatt(mContext, false, mGattCallback);
特征被正确读取。在onCharacteristicRead
回调我也断开,靠近盖特:
mBluetoothGatt.disconnect();
mBluetoothGatt.close();
每次我打开一个片段来读取的特性(不管它是否是同一设备或不)clientIf
值增加。我可以在logcat中看到:直到clientIf
值等于10,BLE扫描停止寻找任何设备
D/BluetoothGatt: onClientRegistered() - status=0 clientIf=6
D/BluetoothGatt: onClientRegistered() - status=0 clientIf=7
D/BluetoothGatt: onClientRegistered() - status=0 clientIf=8
D/BluetoothGatt: onClientRegistered() - status=0 clientIf=9
D/BluetoothGatt: onClientRegistered() - status=0 clientIf=10
一切正常,我无法连接到我的任何设备读取任何特性等,以及logcat的无限显示这些消息:
D/BluetoothGatt: unregisterApp() - mClientIf=0
D/BluetoothGatt: onClientRegistered() - status=133 clientIf=0
修复它是杀死该应用,然后重新启动,或通过将其关闭,并手动重新启动上的蓝牙的唯一方法。我只在某些设备上遇到此问题,例如Xperia Z1(Android KitKat)和Galaxy S4(Android Lollipop)。我无法在运行Android Marshmallow的Xperia Z3 Compact上重现此问题...
有什么我可以做的吗?我已经尝试了多个“解决方案”,例如 - 从UI线程调用所有BLE方法并关闭/断开GATT,但没有任何帮助。我该如何解决它?
我也有类似的问题,我将断开之间有点延迟扫描解决这个问题也是。谢谢! – Tijn
我找到了和你一样的解决方案。详情:https://github.com/googlesamples/android-BluetoothLeGatt/issues/44 –