I have an android app that read health data from Samsung Health and browse it. I added Samsung Health sdk version 1.4.0 and started to fetch the data using HealthDataResolver.ReadRequest to read different data values like total step counts, distance and active time. I could read the count of steps and distance from HealthConstants.StepCount. I read all the steps records and calcuated the sum of all these records values but the result was equal to the steps count when choosing Mobile phone + All steps. My question is how can I choose the data which I want to fetch (Mobile phone or all steps).
private void readSteps(){
HealthDataResolver resolver = new HealthDataResolver(mStore, null);
HealthDataResolver.Filter filter = null;
if(mReadDataRequest.getStartTime() != 0.0)
filter = HealthDataResolver.Filter.greaterThanEquals(HealthConstants.StepCount.START_TIME, mReadDataRequest.getStartTime());
HealthDataResolver.ReadRequest request = new HealthDataResolver.ReadRequest.Builder()
.setDataType(HealthConstants.StepCount.HEALTH_DATA_TYPE)
.setTimeBefore(Calendar.getInstance().getTimeInMillis())
.setFilter(filter)
.build();
try {
resolver.read(request).setResultListener(result -> {
ArrayList<BaseHealthKit> stepCounts = null;
try {
for (HealthData data : result) {
int count = data.getInt(HealthConstants.StepCount.COUNT);
double distance = data.getDouble(HealthConstants.StepCount.DISTANCE);
String startTime = data.getString(HealthConstants.StepCount.START_TIME);
String endTime = data.getString(HealthConstants.StepCount.END_TIME);
float burnedCalorie = data.getFloat(HealthConstants.StepCount.CALORIE);
if (stepCounts == null)
stepCounts = new ArrayList<>();
StepCount stepCount = new StepCount();
if (startTime != null)
stepCount.setStartTime(Long.parseLong(startTime));
if (endTime != null)
stepCount.setEndTime(Long.parseLong(endTime));
stepCount.setCount(count);
stepCount.setDistance(distance);
stepCount.setmBurnedCalories(burnedCalorie);
stepCounts.add(stepCount);
}
} finally {
result.close();
}
if (mReadDataListener != null)
mReadDataListener.onSucceedReading(stepCounts);
});
} catch (Exception e) {
Log.e(TAG, "Getting sleep data fails.", e);
} finally {
disconnect();
}
}