insert

Inserts a set of data into the Samsung Health app with simplified code. It enables you to insert health data with a specific data type and building an InsertDataRequest easily. To insert data asynchronously, use HealthDataStore.insertDataAsync.

When inserting multiple data, the data insertion process handles each one sequentially. If one data insertion fails, none of them are inserted.

Verify that all properties of data to be inserted have been correctly set. Especially those marked as mandatory and ensure their values are within the available range as the data specifications. Otherwise, this function will throw the ERR_INVALID_INPUT.

The below sample code shows how to insert health data.

val healthDataStore = HealthDataService.getStore(context) // get the store instance from the SDK
val now = Instant.now()
val deviceId = "V13yIaU71n"   // get the device ID using the DeviceManager
val clientDataId = "a1b23cde" // your app's data ID
val bpHealthDataPoint= HealthDataPoint.builder()
            .setStartTime(now)
            .setEndTime(now)
            .setDeviceId(deviceId)
            .setClientDataId(clientDataId)
            .addFieldData(DataType.BloodPressureType.SYSTOLIC, 119F)
            .addFieldData(DataType.BloodPressureType.DIASTOLIC, 87F)
            .addFieldData(DataType.BloodPressureType.MEAN, 0F)
            .addFieldData(DataType.BloodPressureType.PULSE_RATE, 76F)
            .build()

healthDataStore.insert(DataTypes.BLOOD_PRESSURE){
    addData(bpHealthDataPoint)
}

Since

1.0.0

Parameters

type

A data type to be inserted.

builder

A lambda function to build the InsertDataRequest according to the data type.

Preferences Submitted

You have successfully updated your cookie preferences.