【问题标题】:When does the BluetoothGattCallback and onConnectionStateChange been called in Android for BLE?何时在 Android 中为 BLE 调用 BluetoothGattCallback 和 onConnectionStateChange?
【发布时间】:2014-04-22 09:05:31
【问题描述】:

我正在研究适用于 Android 的低功耗蓝牙(BLE,蓝牙 4.0)。

我已经参考了类似链接的文档:Bluetooth Low Energy

它使用connectGatt()方法连接到device-A上的GATT服务器,如下所示。

mBluetoothGatt = device_A.connectGatt(this, false, mGattCallback);

它在mGattCallback中有onConnectionStateChangeonCharacteristicRead等。

The question is:

1. BluetoothGattCallback 何时被调用?

2。当device-Adevice-A 上的所有特征有任何更改时,mBluetoothGatt 中的onConnectionStateChange 是否会返回消息? ,还是只返回我所连接的特征??

【问题讨论】:

    标签: android bluetooth bluetooth-lowenergy


    【解决方案1】:

    首先在连接之后(您作为 gatt-client 连接到作为 gatt-server 的设备),您应该调用 Discovery 设备的服务。之后该设备可以向您发送onCharacteristicChanged,以防发生某些变化。 但是在某些情况下,BLE 设备可以作为 gatt-client 并且应该将writeCharacteristic 发送到您的BluetoothGattServer。在这种情况下,您应该创建 gatt-server 并接听电话。

    【讨论】:

    • 谢谢,我已经使用电池服务从 BLE 设备获取电池。这是否意味着Android端的BluetoothGattServer?
    • @Wun 我猜不,您只是从 BLE 设备(gatt-server)读取(作为 gatt-client)电池特性。 Gatt-server 是那些提供服务的。
    • @KonstantinKonopko 你能帮我解决这个问题吗:stackoverflow.com/questions/53099824/…
    猜你喜欢
    • 1970-01-01
    • 2015-10-04
    • 2014-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多