2. Set up Bluetooth Low Energy (BLE)
Get Bluetooth Adapter :
Enable Bluetooth :
3. Find BLE Devices
To find BLE devices, you use the startLescan() method
mLeScanCallback is the interface used to deliver BLE scan results
4. Connect to GATT server
The first step in interacting with a BLE device is connecting to it— more
specifically, connecting to the GATT server on the device. To connect to a GATT server
on a BLE device, you use the connectGatt() method.
• A Context object, autoConnect (boolean indicating whether to
automatically connect to the BLE device as soon as it becomes
available), and a reference to a BluetoothGattCallback
• connectGatt() used for connecting to the GATT server
• BluetoothGatt instance, which you can then use to conduct GATT
client operations
• The Android app is the GATT client
• The BluetoothGattCallback is used to deliver results to the client
5. Connect to GATT server
The BLE app provides an activity (DeviceControlActivity) to connect, display
data, and display GATT services and characteristics supported by the device. Based on
user input, this activity communicates with a Service called BluetoothLeService, which
interacts with the BLE device via the Android BLE API.
6. Read BLE Attributes
Once your Android app has connected to a GATT server and discovered
services, it can read and write attributes.
Receive GATT Notifications
It's common for BLE apps to ask to be notified when a particular
characteristic changes on the device.
Once notifications are enabled for a characteristic,
an onCharacteristicChanged() callback is triggered if the characteristic
changes on the remote device
7. Close Client (Android App)
Once your app has finished using a BLE device, it should call close() so the system can
release resources appropriately