The onBondStateChanged() method in BluetoothGattCallback is used to listen for changes in the bonding state between the device and a remote device. It is called when the bond state changes, such as when the devices are bonded, bonding, or broken. Thi
The onBondStateChanged()
method in BluetoothGattCallback
is called when a bond state between the device and a remote device changes, such as bonded, bonding, or broken.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
onBondStateChanged()
method in BluetoothGattCallback
is:🎜rrreee🎜The following code sample shows you how to use the onBondStateChanged()
method:🎜rrreee🎜What is the purpose of BluetoothGattCallback.onBondStateChanged() method in android?🎜🎜The onBondStateChanged()
method in BluetoothGattCallback
is used to listen for changes in the bonding state between the device and a remote device. This can be used to update the UI or take other actions based on the bond state.🎜The above is the detailed content of android bluetoothgattcallback bond. For more information, please follow other related articles on the PHP Chinese website!