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 anInsertRequest
instance.Mandatory information Description Data type Set the data type with:
Source device The device ID that provides health data. Set it with:
Data's mandatory properties Set mandatory properties of the health data type by referring to:
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, seeHealthConstants.BloodGlucose.GLUCOSE
data.putFloat(HealthConstants.BloodGlucose.GLUCOSE, value);
An
InsertRequest
instance is created byInsertRequest.Builder.build()
with setting the data type.
It's ready to add data to Samsung Health if thedata
is added to theInsertRequest
.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 inHealthResultHolder.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface and Description static class
HealthDataResolver.InsertRequest.Builder
This class is a builder to configureHealthDataResolver.InsertRequest
.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description void
addHealthData(HealthData object)
Adds health data to insert.void
addHealthData(List<HealthData> objectList)
Adds a health data list to insert.
-
-
-
Method Detail
-
addHealthData
void addHealthData(HealthData object)
Adds health data to insert.- Parameters:
object
- The health data instance. The source device ofobject
should be valid.- Throws:
IllegalArgumentException
- If source device is not set or data isnull
- 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 isnull
- Since:
- 1.0.0
-
-