start Server
Initializes and starts the GATT server with predefined services and characteristics.
This method performs three operations in sequence:
Opens a GATT server with the gattServerCallback to handle client interactions
Adds predefined services and characteristics via addServices
Starts BLE advertising to make this peripheral discoverable via startAdvertising
After calling this method, the device will be visible to nearby BLE scanners and will accept incoming connections. Connected centrals can then discover services, read/write characteristics, and subscribe to notifications.
Prerequisites
Bluetooth must be enabled on the device
Required runtime permissions must be granted (BLUETOOTH_ADVERTISE, BLUETOOTH_CONNECT for API 31+)
The device must support BLE peripheral mode (check via BluetoothAdapter.isMultipleAdvertisementSupported)
Example
// Check prerequisites before starting
if (bluetoothAdapter.isEnabled && bluetoothAdapter.isMultipleAdvertisementSupported) {
gattServer.startServer()
Log.d(TAG, "GATT server started successfully")
} else {
Log.e(TAG, "Device does not support BLE peripheral mode")
}See also
Throws
if required Bluetooth permissions are not granted