Skip to main content

DreisamLib SDK Development Documentation

1. Overview

DreisamLib is an SDK designed for device connection and data interaction (such as blood glucose data synchronization and real-time acquisition). It provides core capabilities including device binding, login, connection management, data synchronization, and heartbeat detection, and is suitable for scenarios involving interaction with blood glucose monitoring devices.

2. Initialization

2.1 Pre-initialization

Function Description

Cold start experience of the App.
  • Function: SDK pre-initialization, must be called in the main thread of the Application.onCreate function.
  • Features:
    • Minimal time consumption, does not affect the first cold start experience of the App.
    • Does not collect device information.
  • Parameter: context - Application context (Application instance).
public static void preInit(Application context)

Parameter Description

Parameter NameTypeDescription
contextApplicationApplication context of the app

Usage Example

public class MyApplication extends Application {
   @Override
   public void onCreate() {
       super.onCreate();
       // Pre-initialize the SDK
       DreisamLib.preInit(this);
  }
}

2.2 Official Initialization

Function Description

Complete the core initialization of the SDK, to be called afterwards with minimal time consumption, without affecting the main thread, and it must be called.
public static void initSDK(String appdId, DreisamLibBuilder builder)

Parameter Description

Parameter NameTypeDescription
appdIdStringUnique application identifier obtained from the development platform
builderDreisamLibBuilderInitialization configuration builder

Usage Example

// Build configuration
DreisamLibBuilder builder = new DreisamLibBuilder();
builder.setHideLog(false); // Show logs
// Official initialization
DreisamLib.initSDK("your_appdid", builder);

2.3 Initialization Configuration Class (DreisamLibBuilder)

MethodDescriptionParameter
setHideLog(boolean hideLog)Set whether to hide logshideLog: true (hide, default) / false (show)
isHideLog()Get the log hiding status-

3. Core Function Interfaces

3.1 Connection Precondition Check

Function Description

Check preconditions for device connection such as system authorization and network authentication. Developers can also perform permission checks on their own according to the Demo.
void checkPreConditions(OnPreCheckListener listener)

Parameter Description

Parameter NameTypeDescription
listenerOnPreCheckListenerPrecondition check listener

Listener (OnPreCheckListener)

Callback MethodDescriptionParameter
onSystemPermissionChanged(boolean granted, List<String> missingPermissions)Callback for system authorization status changegranted: whether authorization is passed; missingPermissions: list of missing permissions

3.2 Login

Function Description

User login, associate user platform Token with regional information.
void login(String areaCode, String userToken, OnLoginListener listener)

Parameter Description

Parameter NameTypeDescription
areaCodeStringRegional code
userTokenStringUser platform Token
listenerOnLoginListenerLogin result callback

Listener(OnLoginListener)

Callback MethodDescriptionParameter
loginFail(int code,String msg)Login failedcode: error code; msg: error
loginSucc(boolean hasAvailableDevice, DrisamDeviceModel deviceInfoModel)Login succeededdeviceInfoModel:Device information;hasAvailableDevice:Whether there are available devices

Device Information Model (DrisamDeviceModel)

FieldTypeDescription
deviceSnStringDevice serial number
partnerIdStringProduct ID
estimatedEndAtLongDevice expiration timestamp
iconUrlStringProduct icon URL
statusIntDevice status (0: Unbound; 1: Bound; 2: Activated; 3: Expired)
Note: After successful login, if hasAvailableDevice = true, it means there are available devices, and connection can be directly performed subsequently. If hasAvailableDevice = false, it means there are no available devices, and connection can only be called after successful device binding.

3.3 Logout

Function Description

Logout and clear all user data.
void logout()

3.4 Device Binding

Function Description

Bind a device with a specified name, and the binding process feeds back the status through a listener.
void bindDevice(String deviceName, OnBindListener listener)

Parameter Description

Parameter NameTypeDescription
deviceNameStringDevice name
listenerOnBindListenerBinding status listener

Listener (OnBindListener)

Callback MethodDescriptionParameter
onBindFail(int code, String msg)Binding failedcode: error code; msg: error message
onBindSuccess(DrisamDeviceModel deviceInfoModel)Binding succeededdeviceInfoModel: device information model
onBinding(DreisamBindingEnum bindingCode)Binding in progressbindingCode: binding status enumeration (Checking/Scaning/Connecting/Binding)

Binding Status Enumeration (DreisamBindingEnum)

Enumeration ValueDescription
CHEACKINGChecking
SCANTINGScanning
CONNECTINGConnecting
BINDTINGBinding
Note: After successful binding, there is no need to call the connection method again, as the SDK internally implements the connection operation after binding.

3.5 Device Connection Management

3.5.1 Connect Device

Function Description

According to the information after login, if it returns that there are available devices, connect directly; if there are no available devices, go to bind.
void connectDevice()
Note: The SDK internally implements an automatic reconnection logic, so developers do not need to handle disconnection and reconnection. Only business logic such as updating the UI is required. If the device is disconnected, the SDK will attempt to reconnect after 30 seconds. If the reconnection fails and the App is in the foreground, it will attempt to reconnect again after a delay until the connection is successful; if the App is in the background, frequent operations in the background will cause the application to be suspended due to Android system process management, and it will wait for the heartbeat packet to reconnect again.

3.5.2 Check Device Connection Status

boolean isDeviceConnected()
Return Value
TypeDescription
booleantrue (Connected) / false (Disconnected)

3.5.3 Disconnect Device

void disconnect()

3.5.4 End Device Usage

Function Description
Users end the device cycle on their own, after which the device can no longer be used, and the result is fed back through a callback.
void finishDevice(ValueCallBack<Boolean> valueCallBack)

3.5.5 Connection Status Monitoring

void connectListener(OnConnectListener onConnectListener)
Listener (OnConnectListener)
Callback MethodDescriptionParameter
onConnecState(ConnectingState state)Connection status changestate: connection status enumeration
onConnectSuccess()Connection succeeded-
DreisamConnectEnum (Connection Status Enumeration)
Enumeration ValueDescription
AUTHENTICATION_FAILAuthentication failed
LACK_PERMISSIONPermission missing
DEVICE_CONNECTINGDevice connecting
SHOW_CONNECTINGShowing connecting status
BLE_OFFBluetooth off
NO_AVAILABLE_DEVICENo available device
TOKEN_INVALIDToken invalid
DEVICE_FINISHDevice usage expired
Note: Difference between DEVICE_CONNECTING and SHOW_CONNECTING:
  • DEVICE_CONNECTING is called whenever the device is disconnected
  • SHOW_CONNECTING is the connecting status displayed for users’ attention, and it is only called if the latest data is not up-to-date and the device is not yet connected.

3.6 Heartbeat Detection

3.6.1 Start Heartbeat Detection

Function Description
Used to detect the device connection status, executed every 5 minutes. If not connected, the SDK will try to reconnect to the device. Developers can also implement it on their own.
void startHeartbeat()

3.6.2 Stop Heartbeat Detection

void stopHeartbeat()

3.7 Data Interaction

3.7.1 Data Synchronization Monitoring

Function Description
The callback returns new data that the SDK has not synchronized with the device.
void setSyncDatasListener(OnSyncDatasCallBack callBack)
Listener (OnSyncDatasCallBack)
Callback MethodDescriptionParameter
onSyncStart(int totalCount)Synchronization startedtotalCount: total amount of data to be synchronized
onSyncProgress(int progress)Synchronization progress updatedprogress: progress percentage (0-100)
onSyncComplete(boolean success, List<GlucoseBean> datas)Synchronization completedsuccess: whether successful; datas: list of synchronized blood glucose data

3.7.2 Real-Time Data Callback

Function Description
Data reported by the device, callback once every 3 minutes under normal conditions.
void realTimeDataCallBack(OnAnalzeDatatListener listener)
Listener (OnAnalzeDatatListener)
Callback MethodDescriptionParameter
analzeData(GlucoseBean data)Real-time blood glucose data callbackdata: blood glucose data model

3.7.3 Blood Glucose Data Model (GlucoseBean)

FieldTypeDescription
timeCreateLongData creation timestamp (seconds)
timeSaveLongData saving timestamp (seconds)
packageNumberIntData package number
glucoseFloatBlood glucose value
typeIntData type (1: Initial value/Normal value)
trendIntBlood glucose trend (1: Stable; 5: Rising obliquely; 10: Falling obliquely; 15: Rising vertically; 20: Falling vertically)
Auxiliary MethodDescription-
-----------------
printMessage()Returns a formatted string of blood glucose data-
getTimeCreateStrHM()Returns the data creation time as a string in “Hour:Minute” format-

3.8 Log Monitoring

3.8.1 Connection Log Monitoring

Method Signature
void setConnectLog(OnConnectLogListener onConnectLogListener)
Listener (OnConnectLogListener)
Callback MethodDescriptionParameter
onConnectLog(int state, String msg)Connection log callbackstate: log status code; msg: log information

4. General Callback Interface

5.1 ValueCallBack<T>

MethodDescriptionParameter
succ(T t)Operation success callbackt: data returned on success
fail(int code, String msg)Operation failure callbackcode: error code; msg: error message

5. Usage Flow Example

// 1. Pre-initialize the SDK when the application is initialized
public class MyApp extends Application {
   @Override
   public void onCreate() {
       super.onCreate();
       DreisamLib.preInit(this);
       // 2. Initialize the SDK
       DreisamLibBuilder builder = new DreisamLibBuilder();
       builder.setHideLog(false);
       DreisamLib.initSDK("your_appdid", builder);
  }
}

// 3. Check connection preconditions
ConnectCtrl.getInstance().checkPreConditions(new OnPreCheckListener() {
   @Override
   public void onSystemPermissionChanged(boolean granted, List<String>missingPermissions) {
       if (granted) {
           // Permission passed, perform login
           login();
      } else {
           // Handle missing permissions
           requestPermissions(missingPermissions);
      }
  }
});

// 4. Login
private void login() {
   ConnectCtrl.getInstance().login("cn", "user_token", newValueCallBack<LoginInfoModel>() {
       @Override
       public void succ(LoginInfoModel loginInfoModel) {
           if (!loginInfoModel.hasAvailableDevice) {
               // No available devices, go to bind device
               bindDevice();
          }else{
              // Has available devices, go to connect
              connectDevice(); 
          }
      }

       @Override
       public void fail(int code, String msg) {
           // Handle login failure
      }
  });
}

// 5. Bind device
private void bindDevice() {
   InnerConnectCtrl.getInstance().bindDevice("device_name", new OnBindListener() {
       @Override
       public void onBindFail(int code, String msg) {
           // Handle binding failure
      }

       @Override
       public void onBindSuccess(DrisamDeviceModel deviceInfoModel) {
           // Binding succeeded, connect device
           connectDevice();
      }

       @Override
       public void onBinding(DreisamBindingEnum bindingCode) {
           // Update binding in-progress status
      }
  });
}

// 6. Connect device and monitor status
private void connectDevice() {
  // Monitor data
   dataListener();
   // Set connection status listener
   InnerConnectCtrl.getInstance().connectListener(new OnConnectListener() {
       @Override
       public void onConnecState(ConnectingState state) {
           // Handle connection status changes
      }

       @Override
       public void onConnectSuccess() {
          
      }
  });
   // Connect device
   InnerConnectCtrl.getInstance().connectDevice();
}

// 7. Data monitoring
private void dataListener() {
   // Monitor real-time blood glucose data
   InnerConnectCtrl.getInstance().realTimeDataCallBack(new OnAnalzeDatatListener() {
       @Override
       public void analzeData(GlucoseBean data) {
           // Handle real-time blood glucose data
           Log.d("Glucose", data.printMessage());
      }
  });
   // Monitor data synchronization
   InnerConnectCtrl.getInstance().setSyncDatasListener(new OnSyncDatasCallBack() {
       @Override
       public void onSyncStart(int totalCount) {
           // Synchronization started
      }

       @Override
       public void onSyncProgress(int progress) {
           // Synchronization progress updated
      }

       @Override
       public void onSyncComplete(boolean success, List<GlucoseBean> datas) {
           // Synchronization completed, handle historical data
      }
  });
}

Usage Flow Recommendations

  1. Call preInit() in Application.onCreate() for pre-initialization.
  2. Call initSDK() at an appropriate time to complete official initialization.
  3. Call checkPreConditions() to check preconditions.
  4. Set necessary listeners (connection status, data synchronization, etc.).
  5. After preconditions are met, call login(). If there are available devices, call connectDevice() to connect the device; if there are no available devices, go to bind().
  6. After the device is successfully connected, data synchronization, historical data acquisition, or real-time data reception can be performed.
  7. When no longer in use, call disconnect() to disconnect, and call logout() to release resources if necessary.