Interface HealthDataResolver.InsertRequest

  • Enclosing class:

    public static interface HealthDataResolver.InsertRequest
    This interface is able to make a request to insert health data for the specific health data type.

    Request for Inserting Data

    HealthDataResolver.insert() helps that your application saves a new measured data to Samsung Health.
    The following information is mandatory to build an InsertRequest instance.

    You can make a request instance with

    Inserting Data Example

    You can save health data to Samsung Health with HealthDataResolver.insert() after setting detailed property values of the created HealthData instance.

    The health data framework registers the current device where your application is installed. If the source device is the current device, its ID can be checked as shown below.

       // The state of connection
       private final HealthDataStore mStore;
       public static final String APP_TAG = "MyApp";
       private void insertGlucose(long start, long offset, float value) {
            // Set the source device as the current device
            HealthDevice myDevice = new HealthDeviceManager(mStore).getLocalDevice();
           HealthData data = new HealthData();

    And the data instance's properties including mandatory ones needs to be set.

           // Set properties including mandatory ones
           data.putLong(HealthConstants.BloodGlucose.START_TIME, start);
           data.putLong(HealthConstants.BloodGlucose.TIME_OFFSET, offset);

    The measured data value needs to be set after checking defined data unit.
    Each property in API Reference lets you know it.
    In this case, see HealthConstants.BloodGlucose.GLUCOSE

           data.putFloat(HealthConstants.BloodGlucose.GLUCOSE, value);

    An InsertRequest instance is created by with setting the data type.
    It's ready to add data to Samsung Health if the data is added to the InsertRequest.

           HealthDataResolver.InsertRequest insRequest =
                   new HealthDataResolver.InsertRequest.Builder()
           // Add health data

           HealthDataResolver resolver = new HealthDataResolver(mStore, null);
           try {
           } catch (Exception e) {
               Log.d(APP_TAG, "resolver.insert() fails.");

    HealthDataResolver.insert( sends a request to Samsung Health.
    A data validation exception is received in HealthResultHolder.BaseResult. It gives a request's result state and a number of inserted data.

       private final HealthResultHolder.ResultListener<HealthResultHolder.BaseResult> mIstResult =
                 new HealthResultHolder.ResultListener<HealthResultHolder.BaseResult>(){
           public void onResult(HealthResultHolder.BaseResult result) {
               if(result.getStatus() != STATUS_SUCCESSFUL) {
                   // Check the error
               } else {
                   // Check the count of inserted data
                   Log.d(APP_TAG, "Count of inserted data: " + result.getCount());

    • Method Detail

      • addHealthData

        void addHealthData(HealthData object)
        Adds health data to insert.
        object - The health data instance. The source device of object should be valid.
        IllegalArgumentException - If source device is not set or data is null
      • addHealthData

        void addHealthData(List<HealthData> objectList)
        Adds a health data list to insert.
        objectList - The list of health data objects. The source device for each health data has to be defined in advance.
        IllegalArgumentException - If source device is not set or data list is null