BLE difference of connect () and the connectGatt

Method connect () and connectGatt BLE devices are connected, but with different uses.

connectGatt method under BluetoothDevice class BLE function is to initiate a connection device, and a return value of type BluetoothGatt, using the return value may be the next step.

It is a method in BluetoothGatt connect class function is re-connect, reconnect. If the BLE device and APP has been connected to, but because the device is out of Bluetooth range and connection cut off, then back on when the device is within range, you can reconnect by connect ().

Two logical this method is substantially:

First use connectGatt method initiates a connection, will change the callback callback objects connected state in onConnectionStateChange (required custom objects and override a BluetoothGattCallBack onConnectionStateChange), and returns a BluetoothGatt objects, then BluetoothGatt instantiated, the next connection can call connect reconnect.

Figure posted two API

Method BluetoothGatt attached below the API, we can see that the instance is obtained BluetoothGatt to initiate a call connection connectGatt

Guess you like

Origin blog.csdn.net/Smile_Qian/article/details/82221601