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

时间:2018-12-20 14:03:57

标签: android bluetooth bluetooth-lowenergy gatt bluetooth-gatt

我正在开发同时连接到多个BLE设备的Android应用,此后,我从thos设备永久读取了特征信息,但过了一会儿,我在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);
                    }
                }
            }
    }

任何人都可以帮助我解决此问题,谢谢。

0 个答案:

没有答案