简体   繁体   English

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

[英]BLE Gatt onConnectionStateChanged failed with status 257 in Android

I am developping a Android app that connects to multiple BLE devices at the same time, after that i read characteristic permanently from those devices but after a while, I am getting a status 257 in the onConnectionStateChanged() function, the android documentation doesn't explain what is the reason of the error, or how to fix it.我正在开发一个同时连接到多个 BLE 设备的 Android 应用程序,之后我从这些设备永久读取特征但过了一段时间,我在 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);
                    }
                }
            }
    }

could anyone help me to fix this problem, thanks.谁能帮我解决这个问题,谢谢。

I also didn't find error code 257 in the documentation, but my observation is that this code means that you are trying to connect to a Bluetooth device too many times in too short time.我也没有在文档中找到错误代码 257,但我的观察是此代码意味着您尝试在太短的时间内连接到蓝牙设备的次数太多。 Reconnecting bluetooth on your phone should resolve this issue.重新连接手机上的蓝牙应该可以解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM