【问题标题】:Status is GATT_FAILURE in onConnectionStateChange after many reconnections多次重新连接后,onConnectionStateChange 中的状态为 GATT_FAILURE
【发布时间】:2016-06-26 09:40:15
【问题描述】:

我通过以下方式连接到 ble 设备:

 mBluetoothGatt = device.connectGatt(this.context, false, mGattCallback);

 mBluetoothGatt.disconnect();

但如果我做得很快,那么我会在 onConnectionStateChangemGattCallback 中收到 status=BluetoothGatt.GATT_FAILURE

然后我无法再次连接到 GATT,即使关闭/打开蓝牙也是如此。

只有应用强制停止才能解决问题

【问题讨论】:

    标签: android bluetooth bluetooth-lowenergy gatt


    【解决方案1】:

    当状态为STATE_DISCONNECTED时添加mBluetoothGatt.close();已修复

    private final BluetoothGattCallback mGattCallback =
                new BluetoothGattCallback() {
                    @Override
                    public void onConnectionStateChange(BluetoothGatt gatt, int status,int newState) {
                        String intentAction;
    
                        if (newState == BluetoothProfile.STATE_CONNECTED) {
    
                        } else if (status==133&&newState == BluetoothProfile.STATE_DISCONNECTED) {
                            mBluetoothGatt.close();
                        }else if (status==BluetoothGatt.GATT_FAILURE&&newState == BluetoothProfile.STATE_DISCONNECTED){
    
                        } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
                            mBluetoothGatt.close();
                        }
                    }
    

    【讨论】:

      猜你喜欢
      • 2018-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-08
      相关资源
      最近更新 更多