connect

@CheckReturnValue
abstract fun connect(deviceName: String): Completable

Connect to a remote device identified by the given deviceName.

This also authenticates the device at the remote device, if an apiKey has been set in the SOCommOutsideAPIBuilder. If the authentication fails, an ErrorRespondedException will be emitted.

When calling this method, the following permissions are checked to be already granted. You need to check / request those permissions beforehand. This method will emit a com.swarovskioptik.comm.sdk.exception.PermissionNotGrantedException if permissions have not been granted.

The API requires the following runtime permission to be already granted here:

  • android.Manifest.permission.ACCESS_FINE_LOCATION: Needed to be able to scan for BLE devices. This SDK will never use this permission to query location-specific data, or use the data for location retrieval. But as it is potentially possible to gain information about a users location by scanning BLE devices/beacons, we need to request this permission. Please note, that this is a runtime-permission, which needs to be explicitly granted by the user at runtime, and can be revoked at any time.

The API furthermore requires some permissions, which are enough to be present in the AndroidManifest file (which the SDK adds to the application manifest file, so you should not need to take any actions here). Those are:

  • BLUETOOTH (SDK level < 31 only): Needed for bluetooth connectivity

  • BLUETOOTH_ADMIN (SDK level < 31 only): Needed to be able to start & stop bluetooth

  • BLUETOOTH_SCAN (SDK level >= 31 only): Needed to scan for the desired device to connect to

  • BLUETOOTH_CONNECT (SDK level >= 31 only): Needed to connect to paired BLE devices

  • ACCESS_WIFI_STATE: Needed to be able to check WIFI connectivity.

  • ACCESS_NETWORK_STATE: Needed to be able to check whether wifi connection is active / has been set up correctly.

  • CHANGE_WIFI_STATE: Needed to be able to change the WIFI network.

  • INTERNET: Needed to be able to create a socket for MQTT communication.

Moreover, bluetooth must be enabled before calling this method. Otherwise, a BluetoothNotEnabledException will be emitted (or, if no bluetooth adapter could be found, a BluetoothNotAvailableException will be emitted).

Note, that subsequent calls to connect, while another Completable from connect is still running, will result in an error.

Scheduler: The returned Completable will operate on the IO Scheduler.

Return

a Completable which completes once the connection has been established successfully.

Parameters

deviceName

the (BLE) device name of the remote device to connect to.

See also