6

我有Android应用程序公开BLE服务器。我连接BluetoothGattServer#connect。它的工作原理 - 我的应用程序通过STATE_CONNECTED致电BluetoothGattServerCallback#onConnectionStateChange。当我完成客户端时,我尝试使用BluetoothGattServer#cancelConnection与我的应用断开连接。BluetoothGattServer cancelConnection不取消连接

但我不明白来电BluetoothGattServerCallback#onConnectionStateChange,似乎连接仍然活跃,我的BLE客户没有开始做广告(这确实没事的时候连接到它)。

在logcat中我只看到:

BluetoothGattServer: cancelConnection() - device: XX:XX:XX:XX:XX:XX 

有趣的是,我的应用程序变得只要我完全关闭BT与STATE_DISCONNECTED来电BluetoothGattServerCallback#onConnectionStateChange

Google跟踪器中的类似问题:6346163464

+0

IIRC cancelConnection被完全破碎上大多数早期的器件时的Android BLE首先出来,谷歌决定不解决这个问题。 – reTs

+0

你有没有设法找到解决办法?我正在为同样的事情奋斗 –

+0

不是 - 我决定尽可能远离BLE,永远不要再靠近。 –

回答

1

调用disconnect()方法时遇到同样的问题..我的BluetoothGattCallback中的onConnectionStateChange中没有给出断开连接。

自行车蓝牙似乎是唯一可行的。

编辑: 也断开()和close()方法之后是所谓的,我仍然根据这个代码连接:

public int getConnectedBLEDevices() { 
     int i = 0; 
     List<BluetoothDevice> devices = mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT); 
     for(BluetoothDevice device : devices) { 
      if(device.getType() == BluetoothDevice.DEVICE_TYPE_LE) { 
       Logs.writeEvent(TAG+".getConnectedBLEDevices()", device.getAddress() + "\n"+ getStateAsString(mBluetoothManager.getConnectionState(device, BluetoothProfile.GATT))); 
       i++; 
      } 
     } 
     return i; 
    } 
+0

你是什么意思“循环蓝牙似乎是唯一可行的。”? –

+0

打开和关闭蓝牙 – user1064249

+0

您是否设法找到此问题的解决方法?我正在同样的事情上挣扎 –