Class BluetoothLE
The BLE central role: scanning for peripherals and re-obtaining known
ones. Obtain via Bluetooth.getInstance().getLE(); the instance is
owned by the active port and never null -- on ports without BLE it
reports every operation as unsupported.
Any number of scans may run concurrently. This base class multiplexes
them over a single platform scan: each BleScan handle only receives
advertisements matching its own ScanSettings filters, and the
platform scan stops when the last handle stops.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidfireScanFailed(BluetoothException reason) Reports that the OS aborted the platform scan; every active handle fails with the given reason and the registry is cleared.protected final voidfireScanResult(ScanResult result) Reports one advertisement sighting from the platform scan; safe to call from any thread.protected final List<ScanSettings> The settings of all currently active scan handles -- for ports that optimize the platform scan.protected final ScanModeThe most aggressiveScanModeamong the active handles -- convenience for ports mapping the merged scan onto a platform scan mode.The LE peripherals bonded with this device.getConnectedPeripherals(BluetoothUuid serviceFilter) The peripherals the system currently holds connected (e.g. paired wearables), optionally filtered to those offering the given service.getPeripheral(String address) Re-obtains a peripheral from an address persisted earlier (seeBluetoothDevice.getAddress()for the address semantics) without scanning.protected booleantruewhen this port can scan; the base class returnsfalse, makingstartScan(ScanSettings, ScanListener)fail fast.protected voidCalled after every scan registration change.openGattServer(GattServerListener listener) Opens the local GATT server for the peripheral role; the listener's methods fire on the EDT.openL2capServer(boolean secure) Opens a listening L2CAP endpoint for the peripheral role; publishL2capServer.getPsm()to centrals (typically via a GATT characteristic).startAdvertising(AdvertiseSettings settings, AdvertiseData data, AdvertiseData scanResponse) Starts advertising.protected voidStarts the single underlying platform scan; called when the firstBleScanhandle registers.final BleScanstartScan(ScanSettings settings, ScanListener listener) Starts scanning; the listener fires on the EDT for every advertisement passing the settings' filters.protected voidStops the underlying platform scan; called when the last handle stops.
-
Constructor Details
-
BluetoothLE
protected BluetoothLE()Ports construct subclasses. Application code obtains the active instance viaBluetooth.getInstance().getLE().
-
-
Method Details
-
startScan
Starts scanning; the listener fires on the EDT for every advertisement passing the settings' filters. Returns a liveBleScanhandle -- keep a reference and callBleScan.stop()when done. On ports without BLE the returned handle is already failed withBluetoothError.NOT_SUPPORTED. -
getPeripheral
Re-obtains a peripheral from an address persisted earlier (seeBluetoothDevice.getAddress()for the address semantics) without scanning. Returnsnullwhen the platform cannot resolve the address. -
getConnectedPeripherals
The peripherals the system currently holds connected (e.g. paired wearables), optionally filtered to those offering the given service. Empty on ports without BLE.
iOS filters exactly (CoreBluetooth resolves services); Android can only consult its cached SDP/GATT UUIDs, so the filter is best-effort there and devices with an empty cache are retained.
-
getBondedPeripherals
The LE peripherals bonded with this device. Empty on ports without BLE or without a bonded-device registry (iOS). -
openGattServer
Opens the local GATT server for the peripheral role; the listener's methods fire on the EDT. Fails withBluetoothError.NOT_SUPPORTEDon ports without peripheral mode -- branch viaBluetooth.getInstance().isPeripheralModeSupported(). -
startAdvertising
public AsyncResource<BleAdvertisement> startAdvertising(AdvertiseSettings settings, AdvertiseData data, AdvertiseData scanResponse) Starts advertising. Resolves with a liveBleAdvertisementhandle once the platform actually started broadcasting, or fails withBluetoothError.ADVERTISE_FAILED/BluetoothError.NOT_SUPPORTED.scanResponsemay benull. -
openL2capServer
Opens a listening L2CAP endpoint for the peripheral role; publishL2capServer.getPsm()to centrals (typically via a GATT characteristic). Fails withBluetoothError.NOT_SUPPORTEDwhere L2CAP or peripheral mode is unavailable. -
isScanSupported
protected boolean isScanSupported()truewhen this port can scan; the base class returnsfalse, makingstartScan(ScanSettings, ScanListener)fail fast. -
startPlatformScan
protected void startPlatformScan()Starts the single underlying platform scan; called when the firstBleScanhandle registers. Sightings are reported viafireScanResult(ScanResult). May throw aRuntimeExceptionto fail the initiating handle. -
stopPlatformScan
protected void stopPlatformScan()Stops the underlying platform scan; called when the last handle stops. -
onScanRegistrationsChanged
protected void onScanRegistrationsChanged()Called after every scan registration change. Ports may retune the platform scan (e.g. push down filters or raise the scan mode) based ongetActiveScanSettings(). Default does nothing. -
getActiveScanSettings
The settings of all currently active scan handles -- for ports that optimize the platform scan. -
getAggregateScanMode
-
fireScanResult
Reports one advertisement sighting from the platform scan; safe to call from any thread. The base class demultiplexes it to every active handle whose filters match, applying per-handle duplicate suppression, and dispatches the listeners on the EDT. -
fireScanFailed
Reports that the OS aborted the platform scan; every active handle fails with the given reason and the registry is cleared. The base class does NOT callstopPlatformScan()on this path -- the platform scan is presumed dead, so ports must clean up their own scanner state before (or when) calling this.
-