Package 

Class RxBleClient

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      public enum RxBleClient.State
    • Method Summary

      Modifier and Type Method Description
      static RxBleClient create(@NonNull() Context context) Returns instance of RxBleClient using application context.
      static void setLogLevel(int logLevel) A convenience method.Sets the log level that will be printed out in the console.
      static void updateLogOptions(LogOptions logOptions) Method for updating logging options.
      abstract RxBleDevice getBleDevice(@NonNull() String macAddress) Obtain instance of RxBleDevice for provided MAC address.
      abstract Set<RxBleDevice> getBondedDevices() A function returning a set of currently bonded devicesIf Bluetooth state is not STATE_ON, this API will return an empty set.
      abstract Set<RxBleDevice> getConnectedPeripherals() A function returning a set of currently connected devices (NOTE: Connected to the phone, not necessarily application)
      abstract Observable<RxBleScanResult> scanBleDevices(@Nullable() Array<UUID> filterServiceUUIDs) Returns an infinite observable emitting BLE scan results.Scan is automatically started and stopped based on the Observable lifecycle.Scan is started when the Observable is subscribed and stopped when unsubscribed.You can safely subscribe multiple observers to this observable.
      abstract Observable<ScanResult> scanBleDevices(ScanSettings scanSettings, Array<ScanFilter> scanFilters) Returns an infinite observable emitting BLE scan results.Scan is automatically started and stopped based on the Observable lifecycle.Scan is started on subscribe and stopped on unsubscribe.
      abstract BackgroundScanner getBackgroundScanner() Returns a background scanner instance that can be used to handle background scans, even if your process is stopped.
      abstract Observable<RxBleClient.State> observeStateChanges() Returns an observable emitting state _changes_ of the RxBleClient environment which may be helpful in deciding if particularfunctionality should be used at a given moment.
      abstract RxBleClient.State getState() Returns the current state of the RxBleClient environment, which may be helpful in deciding if particular functionalityshould be used at a given moment.
      abstract boolean isScanRuntimePermissionGranted() Returns whether runtime permissions needed to run a BLE scan are granted.
      abstract boolean isConnectRuntimePermissionGranted() Returns whether runtime permissions needed to start a BLE connection are granted.
      abstract Array<String> getRecommendedScanRuntimePermissions() Returns permission strings needed by the application to run a BLE scan or an empty array if no runtime permissions are needed.
      abstract Array<String> getRecommendedConnectRuntimePermissions() Returns permission strings needed by the application to connect a BLE device or empty array if no runtime permissions are needed.No runtime permissions were needed for connecting a BLE device up to Android 12.0.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • create

         static RxBleClient create(@NonNull() Context context)

        Returns instance of RxBleClient using application context. It is required by the client to maintain single instance of RxBleClient.

        Parameters:
        context - Any Android context
      • setLogLevel

        @Deprecated() static void setLogLevel(int logLevel)

        A convenience method.Sets the log level that will be printed out in the console. Default is LogLevel.NONE which logs nothing.

        Parameters:
        logLevel - the minimum log level to log
      • updateLogOptions

         static void updateLogOptions(LogOptions logOptions)

        Method for updating logging options. Properties not set in LogOptions will not get updated.

        Default behaviour: MAC addresses are not logged (MAC='XX:XX:XX:XX:XX:XX'), uuids are not logged (uuid='...'), byte array valuesare not logged (value=[...]), logger is logging to the logcat (android.util.Log), all scanned peripherals are logged iflog level allows it, log level is set not to log anything (NONE)

        Parameters:
        logOptions - the logging options
      • getBleDevice

         abstract RxBleDevice getBleDevice(@NonNull() String macAddress)

        Obtain instance of RxBleDevice for provided MAC address. This may be the same instance that was provided during scan operation butthis in not guaranteed.

        Parameters:
        macAddress - Bluetooth LE device MAC address.
      • getBondedDevices

         abstract Set<RxBleDevice> getBondedDevices()

        A function returning a set of currently bonded devicesIf Bluetooth state is not STATE_ON, this API will return an empty set. After turning on Bluetooth, wait for ACTION_STATE_CHANGEDwith STATE_ON to get the updated value.Calling this function on or above Android 12 (API >= 31) requires BLUETOOTH_CONNECT runtime permission.

      • getConnectedPeripherals

         abstract Set<RxBleDevice> getConnectedPeripherals()

        A function returning a set of currently connected devices (NOTE: Connected to the phone, not necessarily application)

      • scanBleDevices

        @Deprecated() abstract Observable<RxBleScanResult> scanBleDevices(@Nullable() Array<UUID> filterServiceUUIDs)

        Returns an infinite observable emitting BLE scan results.Scan is automatically started and stopped based on the Observable lifecycle.Scan is started when the Observable is subscribed and stopped when unsubscribed.You can safely subscribe multiple observers to this observable.When defining filterServiceUUIDs have in mind that the RxBleScanResult will be emitted only if _all_ UUIDs are presentin the advertisement.

        The library automatically handles Bluetooth adapter's state changes but you are supposed to promptthe user to enable it if it's disabled.

        Parameters:
        filterServiceUUIDs - Filtering settings.
      • scanBleDevices

         abstract Observable<ScanResult> scanBleDevices(ScanSettings scanSettings, Array<ScanFilter> scanFilters)

        Returns an infinite observable emitting BLE scan results.Scan is automatically started and stopped based on the Observable lifecycle.Scan is started on subscribe and stopped on unsubscribe. You can safely subscribe multiple observers to this observable.

        The library automatically handles Bluetooth adapter state changes but you are supposed to prompt the userto enable it if it is disabledThis function works on Android 4.3 in compatibility (emulated) mode.

        Parameters:
        scanSettings - Scan settings
        scanFilters - Filtering settings.
      • getBackgroundScanner

         abstract BackgroundScanner getBackgroundScanner()

        Returns a background scanner instance that can be used to handle background scans, even if your process is stopped.

      • observeStateChanges

         abstract Observable<RxBleClient.State> observeStateChanges()

        Returns an observable emitting state _changes_ of the RxBleClient environment which may be helpful in deciding if particularfunctionality should be used at a given moment.

      • getState

         abstract RxBleClient.State getState()

        Returns the current state of the RxBleClient environment, which may be helpful in deciding if particular functionalityshould be used at a given moment. The function concentrates on states that are blocking the full functionality of the library.

        Checking order:

        1. Is Bluetooth available?

        2. Is Location Permission granted? (if needed = API>=23)

        3. Is Bluetooth Adapter on?

        4. Are Location Services enabled? (if needed = API>=23)

        If any of the checks fails an appropriate State is returned and next checks are not performed.

        State precedence order is as follows:

        BLUETOOTH_NOT_AVAILABLE if check #1 fails,

        LOCATION_PERMISSION_NOT_GRANTED if check #2 fails,

        BLUETOOTH_NOT_ENABLED if check #3 fails,

        LOCATION_SERVICES_NOT_ENABLED if check #4 fails,

        READY

      • getRecommendedScanRuntimePermissions

         abstract Array<String> getRecommendedScanRuntimePermissions()

        Returns permission strings needed by the application to run a BLE scan or an empty array if no runtime permissions are needed. SinceAndroid 6.0 runtime permissions were introduced. To run a BLE scan a runtime permission is needed ever since. Since Android 10.0a different (finer) permission is needed. Prior to Android 12.0 only a single permission returned by this function is needed toperform a scan. It is up to the user to decide which one. The result array is sorted with the least permissive values first. SinceAndroid 12 all permissions returned by this function are needed.

        Returned values:

        case: API < 23

        Empty array. No runtime permissions needed.

        case: 23 <= API < 29

        ACCESS_COARSE_LOCATIONACCESS_FINE_LOCATION

        case: 29 <= API < 31

        ACCESS_FINE_LOCATION

        case: 31 <= API

        BLUETOOTH_SCAN optionally ACCESS_FINE_LOCATION if BLUETOOTH_SCAN does not have a "neverForLocation" flag

      • getRecommendedConnectRuntimePermissions

         abstract Array<String> getRecommendedConnectRuntimePermissions()

        Returns permission strings needed by the application to connect a BLE device or empty array if no runtime permissions are needed.No runtime permissions were needed for connecting a BLE device up to Android 12.0.

        Returned values:

        case: API < 31

        Empty array. No runtime permissions needed.

        case: 31 <= API

        BLUETOOTH_CONNECT