手機與arduino的HC-06藍牙模塊已經連接成功,但如果arduino掉電,此時藍牙連接就已經斷開,如何判斷這種狀態呢??
在網上搜到的方法是使用廣播,我寫的代碼如下圖。
這是一個歡迎頁面,如果第一次進入app,就跳轉到藍牙連接的頁面,如果不是第一次,但藍牙連接斷開或者藍牙關閉,同樣跳轉到藍牙連接的頁面,藍牙關閉的狀態能判斷,就是斷開連接的狀態無法判斷。
請各位大神指點一二!
uj5u.com熱心網友回復:
device.connectGatt(BluetoothLeService.this, false, mGattCallback);
注冊 BluetoothGattCallback介面,通過onConnectionStateChange的newState欄位判斷是否斷開
if (newState == BluetoothProfile.STATE_DISCONNECTED)
uj5u.com熱心網友回復:
好嘞,謝謝,我試一下????
uj5u.com熱心網友回復:
您好,您在上面寫的device.connectGatt(BluetoothLeService.this, false, mGattCallback);
我沒找到有BluetoothLeService
只有BluetoothLeAdvertiser
BluetoothLeScanner
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/43971.html
標籤:Android
下一篇:微信小程式開發的好處有
