public static interface HealthConstants.StepDailyTrend extends HealthConstants.Common
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.
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()); } }
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 of the following extending interfaces are available for this data type.
Step daily trend data has the following properties.
Property name | Description |
---|---|
HealthConstants.StepDailyTrend.DEVICE_UUID | [Mandatory] Device identifier which provides the health data |
HealthConstants.StepDailyTrend.DAY_TIME | [Mandatory] The date of summarized step count data in milliseconds. It indicates 00:00:00 UTC of the date exactly, |
HealthConstants.StepDailyTrend.COUNT | [Mandatory] Total number of daily steps |
HealthConstants.StepDailyTrend.BINNING_DATA | Gathering data of the daily step count for every 10 minutes with the JSON format |
HealthConstants.StepDailyTrend.CALORIE | Total burned calories for daily steps in kilocalories |
HealthConstants.StepDailyTrend.DISTANCE | Total distance for daily steps in meters |
HealthConstants.StepDailyTrend.SOURCE_PKG_NAME | Package name that provides step count data |
HealthConstants.StepDailyTrend.SOURCE_TYPE | Kind of devices |
HealthConstants.StepDailyTrend.SPEED | Average speed of daily steps in meters per second. |
Modifier and Type | Field and Description |
---|---|
static String |
BINNING_DATA
A set of step count data for every 10 minutes with the JSON format.
|
static String |
CALORIE
Total burned calories for daily steps in kilocalories.
|
static String |
COUNT
Total number of daily steps.
|
static String |
DAY_TIME
The date of summarized step count data in milliseconds.
|
static String |
DISTANCE
Total distance for daily steps in meters.
|
static String |
HEALTH_DATA_TYPE
Data type name for step daily trend data.
|
static String |
SOURCE_PKG_NAME
Package name that provides step count data.
|
static String |
SOURCE_TYPE
Kind of data sources like a connected accessory device.
|
static int |
SOURCE_TYPE_ALL
All data sources, including:
Partner apps only
Local device (phone)
Connected accessory devices like Galaxy Watch or activity trackers
Samsung Health creates one
StepDailyTrend data record for each SOURCE_TYPE everyday. |
static int |
SOURCE_TYPE_PARTNER_APP
Each partner app.
|
static int |
SOURCE_TYPE_PHONE_ONLY
Phone only.
|
static String |
SPEED
Average speed of daily steps in meters per second.
|
CREATE_TIME, CUSTOM, DEVICE_UUID, PACKAGE_NAME, UPDATE_TIME, UUID
static final String DAY_TIME
00:00:00
UTC of the date exactly.
long
static final String COUNT
int
static final String BINNING_DATA
COUNT
gives just a total step count. You can use this info to track more detailed step activity.
byte[]
JSON key | Type |
---|---|
"count" | int |
"calorie" | float |
"distance" | float |
"speed" | 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
,
Constant Field Valuesstatic final String CALORIE
float
static final String DISTANCE
float
static final String SOURCE_PKG_NAME
SOURCE_TYPE
is SOURCE_TYPE_ALL
or SOURCE_TYPE_PHONE_ONLY
,
this value is com.sec.android.app.shealth
.
String
static final String SOURCE_TYPE
HealthConstants.Common.DEVICE_UUID
that indicates data's each source device.
int
static final int SOURCE_TYPE_ALL
StepDailyTrend
data record for each SOURCE_TYPE
everyday.
Samsung Health checks steps for each source device continuously and updates the
data records before the next day's 00:00:00
.
If there is no step for STEP_SOURCE_TYPE
, its data record is not created.
Created data is updated every minutes whenever steps are changed in a day
including data for SOURCE_TYPE_ALL
.
SOURCE_TYPE
,
Constant Field Valuesstatic final int SOURCE_TYPE_PARTNER_APP
00:00:00
UTC
if a partner app's step count exists in a day. It doesn't provide today's data
but until yesterday. Use HealthConstants.StepCount
for today's phone step data.
SOURCE_PKG_NAME
to find an wanted partner app.SOURCE_TYPE
,
Constant Field Valuesstatic final int SOURCE_TYPE_PHONE_ONLY
00:00:00
UTC
if the phone's step count exists in a day. It doesn't provide today's data
but until yesterday. Use HealthConstants.StepCount
for today's phone step data.SOURCE_TYPE
,
Constant Field Valuesstatic final String SPEED
float
static final String HEALTH_DATA_TYPE
"com.samsung.shealth.step_daily_trend"
to add permission to the manifest file.Copyright © Samsung Electronics, Co., Ltd. All rights reserved.