Home > Mobile > Android development, judge the state of the bluetooth connection
Android development, judge the state of the bluetooth connection
Time:09-17
Phone HC - 06 bluetooth module is connected with the arduino is successful, but if arduino power, bluetooth connection is disconnected at this time, how to determine the status?? In online search method is to use the radio, I write the code below, This is a welcome page, if the first enter the app, just skip to bluetooth connection page, if not the first time, but the bluetooth connection is broken or bluetooth closed, jump to the same bluetooth connection page, bluetooth closed state can judge, is disconnected state cannot judge, Please tell the great god!
CodePudding user response:
device. ConnectGatt (BluetoothLeService. This false, mGattCallback);
Registered BluetoothGattCallback interface, through onConnectionStateChange newState because fields determine whether disconnect
If (newState because==BluetoothProfile. STATE_DISCONNECTED)