BLE Gatt onConnectionStateChanged在Android中失败,状态为257

vfh0ocws  于 2022-12-16  发布在  Android
关注(0)|答案(1)|浏览(690)

我正在开发一个Android应用程序,该应用程序同时连接到多个BLE设备,之后我从这些设备永久读取特征,但过了一段时间,我在onConnectionStateChanged()函数中获得状态257,Android文档没有解释错误的原因或如何修复它。

public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
            Log.i("TAG","onConnectionStateChange, status : "+status+" parseConnection : "+ GattStatusParse.parseConnection(status)+"  or "+ GattStatusParse.parseConnection(status));
            isConnected = BluetoothProfile.STATE_CONNECTED == newState;
            if (status == BluetoothGatt.GATT_SUCCESS) {
                   if (isConnected) {
                    Log.i(TAG, "GATT connected." + connectedBluethoothDevice.toString());

                    gatt.discoverServices();
              } else {
                     Log.i("TAG"," GATT disconnected " + device.getAddress() + " state of the opération : " + status + " connexion state : " + newState);
                    if (connectedBluethoothDevice.contains(device)) {
                        connectedBluethoothDevice.remove(device);
                    }
             }else{
                if (connectedBluethoothDevice.contains(device)) {                     
                    int mConnectionState = mBluetoothManager.getConnectionState(device, BluetoothProfile.GATT);
                    if(mConnectionState==BluetoothProfile.STATE_DISCONNECTED || mConnectionState==BluetoothProfile.STATE_DISCONNECTING){
                        connectedBluethoothDevice.remove(device);
                    }
                }
            }
    }

有人能帮我解决这个问题吗,谢谢。

y1aodyip

y1aodyip1#

我也没有在文档中找到错误代码257,但我的观察是,这个代码意味着你试图在太短的时间内连接到蓝牙设备太多次。在手机上重新连接蓝牙应该可以解决这个问题。

相关问题