2016-03-11 1 views
3

Je me connecte à un appareil par ble:Statut est GATT_FAILURE dans onConnectionStateChange après plusieurs reconnexions

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

et que

mBluetoothGatt.disconnect(); 

mais si je le fais rapidement alors que je reçois dans status=BluetoothGatt.GATT_FAILUREonConnectionStateChange Je ne peux plus me connecter au GATT, même si j'allume/éteins le Bluetooth.

seule force d'arrêt de l'application peut résoudre le problème

Répondre

2

fixe en ajoutant mBluetoothGatt.close(); lorsque l'état est STATE_DISCONNECTED

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(); 
        } 
       }