BluetoothGattCallback 中的 onBondStateChanged() 方法用於監聽設備與遠端設備之間的綁定狀態的變化。當鍵合狀態發生變化時,例如當裝置被鍵合、鍵合或斷開時,會呼叫它。 Thi
當藍牙之間的綁定狀態時,會呼叫BluetoothGattCallback
中的onBondStateChanged()
方法裝置和遠端裝置發生變化,例如綁定、綁定或損壞。 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
中<code>onBondStateChanged()
方法的語法BluetoothGattCallback 是:🎜rrreee🎜下面的程式碼範例向您展示如何使用onBondStateChanged()
方法:🎜rrreee🎜Android 中BluetoothGattCallback.onBondStateChanged() 方法的用途是什麼? 🎜 🎜BluetoothGattCallback
中的 onBondStateChanged()
方法用於監聽裝置與遠端裝置之間的綁定狀態的變化。這可用於更新 UI 或根據綁定狀態採取其他操作。 🎜以上是android 藍牙gatt回檔債券的詳細內容。更多資訊請關注PHP中文網其他相關文章!