BLE无法连接到已绑定的设备

在连接到Android上的绑定BLE设备时遇到问题。 包括绑定的设备的第一个连接是成功的,我可以读取所有的特征,连接保持稳定。

当我杀了应用程序或手动断开连接,并尝试再次使用相同的代码,除了绑定本身连接到设备,我从Android端断开连接,错误代码22,这意味着“连接被本地主机终止”。

在这两种情况下,我不知道Android平台下有没有什么区别? 我使用的基本上是我可以提供的教程代码,如果有必要,但我已经基本上尝试了所有从更改gatt参数到自动连接/不,添加BluetoothDevice.TRANSPORT_LE作为传输标志,什么都没有。

这个问题不断发生在我的Pixel,Moto G4和所有最新的Nexus设备上。

外设使用高通芯片CSR1010 uEnergy,是广告,需要配对才能建立连接。 以下是连接内容的片段:

 val bondCreated = device.createBond() 

在邦定状态改变的广播接收机中,我调用连接方法。 我试图用这两种方法试验,省略一个和另一个,改变参数,但没有

 bluetoothGatt = device.connectGatt(context, false, gattCallback, BluetoothDevice.TRANSPORT_LE) bluetoothGatt?.connect() 

如果我收到断开信息,我打电话给:

 bluetoothGatt?.close() bluetoothGatt?.disconnect() 

我尝试再次使用上面相同的代码连接

我已经试图在每一个gatt的操作上都拖延,但仍然没有成功。 在Android断开连接后将自动连接更改为true不起作用。

我也尝试了一些第三方iOS应用程序,所有这些连接到设备没有问题。 他们的Android版本总是与我的方式断开连接。

你能提供任何帮助吗? 这将是最高度赞赏。

日志在这里:

D / BleGattController:DEVICE ALREADY BONDED:设备

D / BluetoothGatt:connect() – 设备:40:80:08:AF:DC:6B,auto:false

D / BluetoothGatt:registerApp()

D / BluetoothGatt:onClientRegistered() – status = 0 clientIf = 8

D / BluetoothGatt:onClientConnectionState() – status = 0 clientIf = 8 device = 40:80:08:AF:DC:6B

D / BleGattController $ gattC:onConnectionStateChange 0 – 已连接

D / BleGattController $ gattC:STATE_CONNECTED

D / BluetoothGatt:onConnectionUpdated() – Device = 40:80:08:AF:DC:6B interval = 6 latency = 0 timeout = 500 status = 0

D / BluetoothGatt:onClientConnectionState() – status = 22 clientIf = 8 device = 40:80:08:AF:DC:6B

D / BleGattController $ gattC:onConnectionStateChange 22 – 断开连接

D / BleGattController $ gattC:STATE_DISCONNECTED