LoginSignup
8
8

More than 5 years have passed since last update.

Android BLE 切断コールバックが呼ばれない

Posted at
切断処理
//切断したい時
gatt.disconnect();
gatt.close();

と一気にやってしまうと切断コールバックが呼ばれなくなる場合があるみたい。
以下のようにしたら解決したように見える

切断処理
//切断したい時
gatt.disconnect();

//BluetoothGattCallback
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    if (newState == BluetoothProfile.STATE_DISCONNECTED) {
        gatt.close();    //disconnect()の結果のコールバック来てからclose
    }
}

disconnect=切断 を確認してからclose=閉じる のは当然といえば当然かもしれない・・・

//AndroidBLEのコールバック地獄めちゃくちゃキツくないですか

8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8