Skip to main content

Overview

DreisamLib is an SDK designed for device connection and data interaction. It provides functionalities such as device connection management, data synchronization, and historical data retrieval, making it suitable for the development of applications requiring communication with specific devices.

Pre-initialization

void preInit(Application context)
  • Function: Pre-initializes the SDK, which must be called in the main thread of the Application.onCreate method.
  • Features:
    • Minimal time consumption, without affecting the App’s first cold start experience.
    • No collection of device information.
  • Parameter: context - Application context (Application instance).

Formal Initialization

void initSDK(String appId, DreisamLibBuilder builder)
  • Function: Completes the formal initialization of the SDK.
  • Call Timing: Can be invoked immediately after pre-initialization or delayed in a background thread, but it is mandatory to call this method.
  • Parameters:
    • appId - AppId generated by the open platform.
    • builder - Configuration builder (used to configure SDK parameters).

De-initialization

void unInit()
  • Function: De-initializes the SDK and releases related resources.

Device Connection Management

Check Connection Preconditions

You can check the prerequisites for connection before establishing it, and developers can also perform permission checks independently by referring to the Demo.
void checkPreConditions(OnPreCheckListener listener)
  • Function: Checks connection preconditions such as system authorization and network authentication.
  • Parameter: listener - Pre-check listener for receiving check results.

Connect to a Specified Device

Connect to the specified device by passing in the device information after scanning the device’s QR code. Developers need to handle the binding and connection logic on their own.
  • If it is the first connection, developers can initiate a binding request to the server in the connection success callback.
  • If the device is already bound, simply connect to it based on the device information bound to the server.
void connectDevice(String deviceName)
  • Function: Connects to the device with the specified name.
  • Parameter: deviceName - Name of the device to be connected.

Set Connection Status Listener

void connectListener(OnConnectListener onConnectListener)
  • Function: Sets the device connection status listener.
  • Parameter: onConnectListener - Instance of the connection status listener.
Note: The SDK has a built-in automatic reconnection mechanism. Developers do not need to handle disconnection and reconnection, but only implement business logic such as UI updates. If the device disconnects, the SDK will attempt to reconnect after 30 seconds. If reconnection fails:
  • If the App is running in the foreground, it will retry connecting after a delay until the connection is successfully established.
  • If the App is running in the background, frequent background operations may cause the application to be suspended due to Android system process management. In this case, the SDK will wait for the heartbeat packet to trigger reconnection again.

Check Device Connection Status

boolean isDeviceConnected()
  • Function: Checks whether the device is connected.
  • Return Value: true indicates connected; false indicates disconnected.

Disconnect Device

void disconnect()
  • Function: Disconnects the currently connected device.

Heartbeat Detection

Start Heartbeat Detection

This is used to detect the device connection status and executes once every 5 minutes. If the device is disconnected, the SDK will retry connecting to it. Developers can also implement this logic on their own.
void startHeartbeat()
  • Function: Starts device heartbeat detection.

Stop Heartbeat Detection

void stopHeartbeat()
  • Function: Stops device heartbeat detection.

Set Data Synchronization Listener

void setSyncDatasListener(OnSyncDatasCallBack callBack)
  • Function: Sets the data synchronization status listener.
  • Parameter: callBack - Instance of the synchronization status listener.
Note:
  • Under normal circumstances: The callback returns new data that has not been synchronized between the SDK and the device.
  • When switching to a new mobile phone or logging out: All data will be returned in the callback. Developers can filter the required data according to the last message stored on their own server.

Retrieve Historical Data

void getHistory(long startTime, long endTime, OnHistoryDatasCallBack callBack)
  • Function: Retrieves historical data within the specified time range.
  • Parameters:
    • startTime - Start timestamp (in seconds).
    • endTime - End timestamp (in seconds).
    • callBack - Callback interface for historical data.

Set Real-time Data Callback

Data reported by the device will trigger a callback once every 3 minutes under normal circumstances.
void realTimeDataCallBack(OnAnalzeDatatListener listener)
  • Function: Sets the real-time data analysis callback listener.
  • Parameter: listener - Instance of the real-time data analysis callback.

Set Connection Log Listener

void setConnectLog(OnConnectLogListener onConnectLogListener)
  • Function: Sets the connection log listener.
  • Parameter: onConnectLogListener - Instance of the log listener.

Listener Interfaces

OnPreCheckListener

Connection precondition check listener
public interface OnPreCheckListener {
    /**
     * Callback for system permission status changes
     * @param granted Whether the permission is granted
     * @param missingPermissions List of missing permissions
     */
    void onSystemPermissionChanged(boolean granted, List<String> missingPermissions);
}

OnAnalzeDatatListener

Real-time data analysis listener
public interface OnAnalzeDatatListener {
    void analzeData(DreisamGlucoseModel data);
}

OnConnectListener

Connection status listener
public interface OnConnectListener {
    void onConnecState(DreisamGlucoseModel state);
    void onConnectSuccess();
}

OnConnectLogListener

Connection log listener
public interface OnConnectLogListener {
    void onConnectLog(int state, String msg);
}

OnHistoryDatasCallBack

Historical data callback interface
public interface OnHistoryDatasCallBack {
   void onHistoryDatas(List<DreisamGlucoseModel> datas);
}

OnSyncDatasCallBack

Data synchronization listener
public interface OnSyncDatasCallBack {
    /**
     * Triggered when synchronization starts
     * @param totalCount Total number of data items to be synchronized
     */
    void onSyncStart(int totalCount);

    /**
     * Triggered when synchronization progress is updated
     * @param progress Synchronization progress percentage (0-100)
     */
    void onSyncProgress(int progress);

    /**
     * Triggered when synchronization is completed
     * @param success Whether synchronization is successful
     * @param datas List of synchronized data
     */
    void onSyncComplete(boolean success, List<DreisamGlucoseModel> datas);
}

Enumeration Types

DreisamGlucoseModel

Connection status enumeration
public enum DreisamGlucoseModel{
    AUTHENTICATION_FAIL, // Authentication failed
    LACK_PERMISSION,     // Missing required permissions
    DEVICE_CONNECTING,   // Device is in the process of connecting
    SHOW_CONNECTING,     // Display connection status
    BLE_OFF              // Bluetooth is turned off
}
Note: Difference between DEVICE_CONNECTING and SHOW_CONNECTING:
  • DEVICE_CONNECTING will trigger a callback as soon as the device disconnects.
  • SHOW_CONNECTING is a connection-in-progress state displayed for user attention. A callback will only be triggered if the latest data is not up-to-date and the device is still disconnected.

Data Models

DreisamGlucoseModel

Blood glucose data model
class DreisamGlucoseModel() {
    var timeCreate: Long = 0  // Data creation timestamp (in seconds)
    var timeSave: Long = 0    // Data save timestamp (in seconds)
    var packageNumber: Int = 0 // Package number
    var glucose: Float = 0f   // Blood glucose value
    var type: Int = 1         // Data type (1: Initial value, normal value)
    var trend = 0             // Blood glucose trend (1: Stable, 5: Rising slowly, 10: Falling slowly, 15: Rising rapidly, 20: Falling rapidly)

    // Prints data information
    fun printMessage(): String { ... }
}
  1. Call preInit() in Application.onCreate() for pre-initialization.
  2. Call initSDK() at an appropriate time to complete formal initialization.
  3. Set necessary listeners (connection status, data synchronization, etc.).
  4. Call checkPreConditions() to verify preconditions.
  5. After preconditions are satisfied, call connectDevice() to connect to the device.
  6. Once the device is connected successfully, perform data synchronization, retrieve historical data, or receive real-time data.
  7. When the SDK is no longer needed, call disconnect() to terminate the connection, and call unInit() if necessary to release resources.