public static interface HealthConstants.StepDailyTrend extends HealthConstants.Common
The daily step count trend gives summarized step count data in a day.
HealthConstants.StepCount
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.
HealthConstants.StepDailyTrend
SOURCE_TYPE
SOURCE_TYPE_ALL
// 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()); } }
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.
StepDailyTrend
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 of the following extending interfaces are available for this data type.
HealthConstants.Common
00:00:00
static String
BINNING_DATA
CALORIE
COUNT
DAY_TIME
DISTANCE
HEALTH_DATA_TYPE
SOURCE_PKG_NAME
static int
SOURCE_TYPE_PARTNER_APP
SOURCE_TYPE_PHONE_ONLY
SPEED
CREATE_TIME, CUSTOM, DEVICE_UUID, PACKAGE_NAME, UPDATE_TIME, UUID
static final String DAY_TIME
long
static final String COUNT
int
static final String BINNING_DATA
byte[]
float
When you request to read daily step count data, Samsung Health gives the result as compressed ZIP that contains 144 (one day = 10 minutes * 6 * 24 hours) JSON formatted data with the time order. You can estimate each data's time information by counting the data's order. The following example shows one of JSON formatted data.
{ "count":75 "calorie":4.0864094495773315, "distance":56.0, "speed":0.001272727269679308 }
Its use cases are:
HealthDataUtil
static final String CALORIE
static final String DISTANCE
static final String SOURCE_PKG_NAME
com.sec.android.app.shealth
String
static final String SOURCE_TYPE
HealthConstants.Common.DEVICE_UUID
static final int SOURCE_TYPE_ALL
STEP_SOURCE_TYPE
Created data is updated every minutes whenever steps are changed in a day including data for SOURCE_TYPE_ALL.
static final int SOURCE_TYPE_PARTNER_APP
static final int SOURCE_TYPE_PHONE_ONLY
static final String SPEED
static final String HEALTH_DATA_TYPE
"com.samsung.shealth.step_daily_trend"