【问题标题】:Turning off Bluetooth Adapter not calling onConnectionStateChange Android 8.1.0关闭蓝牙适配器不调用 onConnectionStateChange Android 8.1.0
【发布时间】:2018-04-25 22:28:58
【问题描述】:

在 Android 系统设置中关闭蓝牙会给我们在 Android BluetoothGattCallback.onConnectionStateChange() 调用。但是,当我在 Pixel 或 Nexus 5X (Android 8.1.0) 上尝试时,我没有收到该回调。蓝牙代码是否有一些变化,在蓝牙设置更改时我们没有收到BluetoothProfile.STATE_DISCONNECTED 的通知。我注意到设备断开连接。此外,当关闭 BLE 设备时,回调会被调用。任何见解都值得赞赏!

在此处作为问题提交Google Issue

【问题讨论】:

  • 您必须在连接回调中检查BluetoothGatt.STATE_DISCONNECTINGBluetoothGatt.STATE_DISCONNECTED 而不是BluetoothProfile
  • @HawkPriest BluetoothGattBlueoothProfile 都对 STATE_DISCONNECTED 使用相同的常量。 BluetoothGatt 实现 BluetoothProfile
  • 你能解决这个问题吗?我也遇到了同样的问题。
  • @Adrian 我不是,我不知道他们是否有任何解决方案。我还没来得及想出解决方案就离开了这个项目。

标签: android bluetooth android-bluetooth android-ble bluetooth-gatt


【解决方案1】:

我猜这是意料之中的,或者至少这是一直以来的行为。当蓝牙关闭(或因某种原因死机)时,蓝牙守护进程退出。但同样的过程也会发出 GATT 回调。如果进程终止,它不能发送任何回调。

请改用https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#ACTION_STATE_CHANGED 来检测蓝牙何时关闭,此时您应该关闭所有BluetoothGatt 对象。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-06
    • 1970-01-01
    • 2013-03-31
    相关资源
    最近更新 更多