Android BluetoothGattServer cancelConnection不会取消连接

Android BluetoothGattServer cancelConnection不会取消连接,android,bluetooth-lowenergy,android-bluetooth,gatt,android-ble,Android,Bluetooth Lowenergy,Android Bluetooth,Gatt,Android Ble,我有一个Android应用程序,它公开了一个可扩展的服务器。我与你联系。它可以工作-我的应用程序可以通过。当我使用完客户端后,我会尝试使用断开与我的应用程序的连接 但是我没有接到对的呼叫,而且连接似乎仍然处于活动状态,因为我的BLE客户端没有开始播发(当没有任何连接到它时,它会这样做) 在logcat中,我只看到: BluetoothGattServer: cancelConnection() - device: XX:XX:XX:XX:XX:XX 有趣的是,一旦我完全关闭BT,我的应用程序就

我有一个Android应用程序,它公开了一个可扩展的服务器。我与你联系。它可以工作-我的应用程序可以通过。当我使用完客户端后,我会尝试使用断开与我的应用程序的连接

但是我没有接到对的呼叫,而且连接似乎仍然处于活动状态,因为我的BLE客户端没有开始播发(当没有任何连接到它时,它会这样做)

在logcat中,我只看到:

BluetoothGattServer: cancelConnection() - device: XX:XX:XX:XX:XX:XX
有趣的是,一旦我完全关闭BT,我的应用程序就会被调用


谷歌跟踪器中的类似问题:和。

调用disconnect()方法时遇到相同问题。。我的Bluetooth GattCallback中的onConnectionStateChange中未提供断开连接

自行车蓝牙似乎是唯一有效的方法

编辑: 另外,在调用disconnect()和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;
    }
public int getConnectedBLEDevices(){
int i=0;
List devices=mblueothmanager.getConnectedDevices(BluetoothProfile.GATT);
用于(蓝牙设备:设备){
if(device.getType()==BluetoothDevice.device\u TYPE\u LE){
Logs.writeEvent(TAG+“.getConnectedBLEDevices()”,device.getAddress()+“\n”+getStateAString(mBluetoothManager.getConnectionState(device,BluetoothProfile.GATT));
i++;
}
}
返回i;
}

当newState==BluetoothProfile.STATE_连接时,必须调用BluetoothGattServer.connect()

请看

状态:无法修复(预期行为) 必须调用BluetoothGattServer.connect()将连接标记为已使用,然后调用BluetoothGattServer.disconnect()将其标记为不再使用。然后在超时后,如果没有其他人使用连接,堆栈可以决定断开与远程设备的连接。
如果在建立连接后未调用BluetoothGattServer.connect(),然后堆栈将保持连接,直到某个gatt客户端/服务器应用程序开始使用此连接。

iirc cancelConnection在大多数早期设备上完全中断,当Android ble首次出现时,Google决定不修复此连接。您是否找到了修复此连接的方法?我也在为同样的事情挣扎不-我决定尽可能远离BLE,再也不靠近。你说的“循环蓝牙似乎是唯一有效的东西”是什么意思?打开和关闭蓝牙你找到解决办法了吗?我也在为同样的事情而挣扎,你是基于什么写的?#8,加上我用过它。#16说:三星S8+运行安卓8.0.0版和三星体验9.0版对评论8不起作用。运行安卓8.0.0版的HTC也不工作。哦,我可以用Pixel-8.1作为外设。没有试过三星手机。
@Override
public void onConnectionStateChange(BluetoothDevice device, int status, int newState) {
    super.onConnectionStateChange(device, status, newState);
    if (newState == BluetoothProfile.STATE_CONNECTED){
        mDevice = device;
        mBluetoothGattServer.connect(device, false);
    }else {
        mDevice = null;
    }
}

private void cancelConnection(){
    if (mDevice != null) {
        mBluetoothGattServer.cancelConnection(mDevice);
    }
}