startServer

Initializes and starts the GATT server with predefined services and characteristics.

This method performs three operations in sequence:

  1. Opens a GATT server with the gattServerCallback to handle client interactions

  2. Adds predefined services and characteristics via addServices

  3. 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

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

BleGattServer.addServices

Throws

if required Bluetooth permissions are not granted