public interface LegoDeviceManager
DeviceManagerCallbackListener
and set the listener property
before scanning for and connecting to devices.
Note: Remember to remove attached listener(s) again to avoid memory leaksModifier and Type | Field and Description |
---|---|
static long |
DEFAULT_CONNECT_REQUEST_TIMEOUT
The default connect request timeout in milliseconds
|
Modifier and Type | Method and Description |
---|---|
java.util.List<? extends LegoDevice> |
allDevices()
Returns a list with all known devices regardless of their current connect state.
|
void |
cancelDeviceConnection(LegoDevice device)
Disconnect from a LEGO Device.
|
void |
connectToDevice(android.content.Context context,
LegoDevice device)
Connect to a LEGO Device.
|
java.util.List<? extends LegoDevice> |
devicesInState(LegoDevice.DeviceState connectionState)
Returns a list of devices in the specified device state.
|
long |
getConnectRequestTimeoutInterval() |
java.lang.String |
getSDKVersion() |
boolean |
isAutomaticReconnectOnConnectionLostEnabled() |
void |
registerCallbackListener(DeviceManagerCallbackListener listener)
Add a listener to receive device discovery and connection events
Note, that callbacks are not guaranteed to be delivered in the same order as the listeners are added.
|
void |
scan(android.content.Context context)
Start scanning for LEGO devices
|
void |
setAutomaticReconnectOnConnectionLostEnabled(boolean enabled)
If enabled, the LegoDeviceManager will attempt to reconnect in case of a connection loss, but only if the connection was not closed by the user,
the default value is false.
|
void |
setConnectRequestTimeoutInterval(long timeoutInterval)
If a connect request is not successful within this time interval the connection attempt is cancelled
and the
DeviceManagerCallbackListener.onDidFailToConnectToDevice(LegoDevice, boolean, dk.lego.devicesdk.LDSDKError) is invoked. |
void |
stopScanning()
Stop scanning for LEGO BLE devices
|
void |
unregisterCallbackListener(DeviceManagerCallbackListener listener)
Remove a listener
|
static final long DEFAULT_CONNECT_REQUEST_TIMEOUT
void scan(android.content.Context context)
context
- The Android contextvoid stopScanning()
void connectToDevice(android.content.Context context, LegoDevice device)
DeviceManagerCallbackListener.onDidFailToConnectToDevice(dk.lego.devicesdk.device.LegoDevice, boolean, dk.lego.devicesdk.LDSDKError)
is invoked.context
- The Android contextdevice
- The device to establish a connection tovoid setConnectRequestTimeoutInterval(long timeoutInterval)
DeviceManagerCallbackListener.onDidFailToConnectToDevice(LegoDevice, boolean, dk.lego.devicesdk.LDSDKError)
is invoked.
The default value is 10 seconds.timeoutInterval
- The timeout interval in millisecondslong getConnectRequestTimeoutInterval()
void setAutomaticReconnectOnConnectionLostEnabled(boolean enabled)
LegoDevice.DeviceState.DEVICE_CONNECTION_STATE_INTERROGATING
with an 'unexpected error' (e.g. not closed by user).
If the second connection attempt also fails, no further attempts are made to connect automatically.
If a connection is lost after successful connection (i.e. in state LegoDevice.DeviceState.DEVICE_CONNECTION_STATE_INTERROGATION_FINISHED
)
If the connect-request does not succeed within the connectRequestTimeout no attempt is made to automatically reconnect.enabled
- Whether automatic reconnect should be enabled or notboolean isAutomaticReconnectOnConnectionLostEnabled()
void cancelDeviceConnection(LegoDevice device)
device
- The device to disconnect fromjava.util.List<? extends LegoDevice> devicesInState(LegoDevice.DeviceState connectionState)
LegoDevice.DeviceState.DEVICE_CONNECTION_STATE_DISCONNECTED_ADVERTISING
.connectionState
- The state of the devices.java.util.List<? extends LegoDevice> allDevices()
void registerCallbackListener(DeviceManagerCallbackListener listener)
listener
- The listener to addvoid unregisterCallbackListener(DeviceManagerCallbackListener listener)
listener
- The listener to removejava.lang.String getSDKVersion()