BluetoothGattCallback中的onBondStateChanged()方法用于监听设备与远程设备之间的bonding状态的变化。当键合状态发生变化时,例如当器件被键合、键合或断开时,会调用它。
onBondStateChanged当设备与远程设备之间的绑定状态发生变化(例如绑定、绑定或断开)时,会调用 <code>BluetoothGattCallback
中的 () 方法。onBondStateChanged()
method in BluetoothGattCallback
is called when a bond state between the device and a remote device changes, such as bonded, bonding, or broken.
The syntax for onBondStateChanged()
method in BluetoothGattCallback
is:
<code class="java">public void onBondStateChanged(BluetoothDevice device, int bondState, int previousBondState)</code>
The following code sample shows you how to use the onBondStateChanged()
method:
<code class="java">private BluetoothGattCallback gattCallback = new BluetoothGattCallback() { @Override public void onBondStateChanged(BluetoothDevice device, int bondState, int previousBondState) { super.onBondStateChanged(device, bondState, previousBondState); String bondStateString = "Unknown bond state"; switch (bondState) { case BluetoothDevice.BOND_NONE: bondStateString = "BOND_NONE"; break; case BluetoothDevice.BOND_BONDING: bondStateString = "BOND_BONDING"; break; case BluetoothDevice.BOND_BONDED: bondStateString = "BOND_BONDED"; break; } String previousBondStateString = "Unknown bond state"; switch (previousBondState) { case BluetoothDevice.BOND_NONE: previousBondStateString = "BOND_NONE"; break; case BluetoothDevice.BOND_BONDING: previousBondStateString = "BOND_BONDING"; break; case BluetoothDevice.BOND_BONDED: previousBondStateString = "BOND_BONDED"; break; } Log.d(TAG, "onBondStateChanged() - Device: " + device + " Bond State: " + bondStateString + " Previous Bond State: " + previousBondStateString); } };</code>
The onBondStateChanged()
method in BluetoothGattCallback
BluetoothGattCallback
中onBondStateChanged()
方法的语法是:#🎜🎜#rrreee#🎜 🎜#下面的代码示例展示了如何使用 onBondStateChanged()
方法:#🎜🎜#rrreee#🎜🎜#android 中 BluetoothGattCallback.onBondStateChanged() 方法的用途是什么?#🎜🎜 ##🎜🎜#BluetoothGattCallback
中的 onBondStateChanged()
方法用于监听设备与远程设备之间的绑定状态的变化。这可用于更新 UI 或根据绑定状态执行其他操作。#🎜🎜#以上是android 蓝牙gatt回调债券的详细内容。更多信息请关注PHP中文网其他相关文章!