com.samsung.android.sdk.healthdata

Interface HealthDataResolver.InsertRequest

  • Enclosing class:
    HealthDataResolver


    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 InsertRequest.Builder.build().

    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();
           data.setSourceDevice(myDevice.getUuid());

    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);
           data.putInt(HealthConstants.BloodGlucose.MEASUREMENT_TYPE,
                   HealthConstants.BloodGlucose.MEASUREMENT_TYPE_WHOLE_BLOOD);
       

    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 InsertRequest.Builder.build() 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()
                   .setDataType(HealthConstants.BloodGlucose.HEALTH_DATA_TYPE)
                   .build();
      
           // Add health data
           insRequest.addHealthData(data);

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

    HealthDataResolver.insert(com.samsung.android.sdk.healthdata.HealthDataResolver.InsertRequest) 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>(){
           @Override
           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());
               }
           }
       };

    Since:
    1.0.0
    • Method Detail

      • addHealthData

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

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