This interface defines the user's daily step count trend data.
Getting All Steps
The daily step count trend gives summarized step count data in a day.
It's a common case that the user has a phone and an accessory like a Galaxy Watch.
Sometimes the user can carry the phone and the accessory both.
Or he/she can carry only one device for other times.
If the user carried 'Phone' and 'Watch' both as 1) and 4) sessions,
both devices provide step count data separately.
Their steps are saved with
HealthConstants.StepCount
in
Samsung Health.
Reading HealthConstants.StepCount
of 1) and 4) sessions will give more step count than the user's real steps.
Because the query's result includes duplicated steps of 'Phone' and 'Watch'.
But removing duplications is not easy with a manual handling.
HealthConstants.StepDailyTrend
provides a simple way to get the user's all steps without duplications.
Just set a filter for SOURCE_TYPE
with SOURCE_TYPE_ALL
with a reading query.
// State of connection
private HealthDataStore mStore;
// Resolver instance
private final HealthDataResolver mResolver;
public static long getTodayStartUtcTime() {
Calendar today = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
today.set(Calendar.HOUR_OF_DAY, 0);
today.set(Calendar.MINUTE, 0);
today.set(Calendar.SECOND, 0);
today.set(Calendar.MILLISECOND, 0);
return today.getTimeInMillis();
}
public void readTodayStepCountData() {
// Suppose that the required permission has been acquired already
// Create a filter for today's steps from all source devices
Filter filter = Filter.and(
Filter.eq(StepDailyTrend.DAY_TIME, getTodayStartUtcTime()),
Filter.eq(StepDailyTrend.SOURCE_TYPE, StepDailyTrend.SOURCE_TYPE_ALL));
ReadRequest request = new ReadRequest.Builder()
// Set the data type
.setDataType(StepDailyTrend.HEALTH_DATA_TYPE)
// Set a filter
.setFilter(filter)
// Build
.build();
mResolver = new HealthDataResolver(store, null);
try {
mResolver.read(request).setResultListener(result -> {
long dayTime = 0;
int totalCount = 0;
try {
Iterator iterator = result.iterator();
if (iterator.hasNext()) {
HealthData data = iterator.next();
dayTime = data.getLong(StepDailyTrend.DAY_TIME)
totalCount = data.getInt(StepDailyTrend.COUNT);
}
} finally {
result.close();
}
});
} catch (Exception e) {
Log.e(MainActivity.APP_TAG, e.getClass().getName() + " - " + e.getMessage());
}
}
StepDailyTrend Data's Creation and Update
The user's steps are collected through a phone or connected accessories like a watch.
StepDailyTrend
data is created after the user's steps are detected.
The created StepDailyTrend
data is updated every minutes (usually one minute) if a step count is changed.
A number of StepDailyTrend
data is one for each SOURCE_TYPE
in a day if the source type collects steps.
Especially SOURCE_TYPE_ALL
data exists always if other SOURCE_TYPE
data is created.
Properties
Properties of the following extending interfaces are available for this data type.
Step daily trend data has the following properties.
See more common properties by spreading this section out.
Data Permission
The user's consent is required to read or write this data type.
HealthPermissionManager.requestPermissions() displays a data permission UI to the user.
See
Permission Manager and request data permission.