Samsung Health Daily Steps

Overview

Samsung Health is an engaging app for fitness, wellness, and care. It helps you track your activity data and gain insights from the collected data. It is available for both Android and iOS users.

Moreover, the data from a wearable device like Galaxy Watch or from a mobile phone is synced to Samsung Health. Through Samsung Health Android SDK, you can share the user’s health data. With more than 70 Million Samsung Health users, join and be part of the Samsung Health ecosystem for more services.

Figure 1 Samsung Health Featured Apps

Figure 1 Samsung Health Featured Apps

Objective

Create Today’s Step Counter app with Samsung Health Android SDK to monitor your daily watch steps, phone steps, and all steps.

Setting-up the Environment

Requirements:
  1. a) At least Java SE Development Kit 8

  2. b) Android Studio

  3. c) Galaxy Watch

  4. d) Mobile Phone

Initial Setup:
  1. a) To activate developer mode of Samsung Health, tap the version line 10 times as seen below. Navigate it through Samsung Health > Settings > About Samsung Health.

    Figure 2 Activating Developer Mode

    Figure 2 Activating Developer Mode

  2. b) Open the given Android Application Project.

Application Development

At this part, you’ll create an app that counts your steps in a day. The step data from the Samsung Health can be read from both a Galaxy watch and a phone. Using the Daily Step Count Trend data type, all steps will be retrieved without duplication.

Upon successful implementation of the succeeding steps, you can see the results as follows:

  1. a) All Steps

  2. b) Steps when using Watch

  3. c) Steps when using Phone

Figure 3 Today’s Step App

Figure 3 Today’s Step App

Locate Files

The SDK library is located at lib/samsung-health-data.jar of the project file.

Permission Request

Open HealthDataProvider.java in the Today’s Steps app project. Handling the user’s health data is only available upon user consent.

public static final Set<PermissionKey> PERMISSION_KEY_SET;
static {
    Set<PermissionKey> keyset = new HashSet<>();
    keyset.add(new PermissionKey("com.samsung.shealth.step_daily_trend", PermissionType.READ));
    keyset.add(new PermissionKey(HealthConstants.StepCount.HEALTH_DATA_TYPE, PermissionType.READ));
    PERMISSION_KEY_SET = Collections.unmodifiableSet(keyset);
}

static void requestPermissions(Activity activity, HealthDataStore store,
                               ResultListener<PermissionResult> listener) {
    HealthPermissionManager pmsManager = new HealthPermissionManager(store);
    pmsManager.requestPermissions(PERMISSION_KEY_SET, activity).setResultListener(listener);
}

In you mobile phone, when you connect the created app to Samsung Health, you will need to enable the data permission and select Done.

Figure 4 Permission Request

Figure 4 Permission Request

Daily Step Data Type

There are times that you are carrying a phone while wearing a watch at the same time. And, there are times when you use these separately. Here’s an example scenario:

Figure 5

Timeline:

  1. 1) 9:00 ~ 10:00 – carries both Watch and Phone.

  2. 2) 10:00 ~ 10:40 – carries only Phone.

  3. 3) 10:40 ~ 12:00 – carries only Watch.

  4. 4) 12:00 ~ 13:00 – carries both Watch and Phone.

In 1) and 4), it is possible that the steps counted are duplicated since the user carried both devices at the same time.

The Daily Step Count Trend is useful on these scenarios where users want to read daily steps on multiple devices. The date of each data is recorded as a day_time value, which indicates 00:00:00 TUC of the date.

"com.samsung.shealth.step_daily_trend"
Field Description
"day_time"

[Mandatory]

The date of summarized step count data in milliseconds. It indicates 00:00:00 UTC of the date exactly.

"count"

[Mandatory]

Total number of daily steps.

"source_type"

Kind of devices.

All device is “-2”

Table 1 Daily Step Trend Data Types

Practice for Reading All Device’s Steps

Conditions to get today’s steps for all devices are part of the filter as seen below:

  1. a) Today’s day_time

  2. b) "-2" source type for all devices

Filter filter = Filter.and(
        // filter for today
        Filter.eq("day_time", Util.getTodayStartTime()),
        // filter for all devices
        Filter.eq("source_type", -2)
);

Set the data type to read all steps.

/*********************************************************************************
 * [Practice] Build read request for today's all step 
 *    - Set data type of calculated step count 
 ----------------------------------------------------------------------------------
 *    - (Hint) Fill below TODO 1 with "com.samsung.shealth.step_daily_trend""
 *********************************************************************************/
ReadRequest request = new ReadRequest.Builder()
        .setDataType("TODO 1")
        .setFilter(filter)
        .build();

Result Check

Run the Today’s Steps app and check its results if it shows the following health data:

  1. a) All steps

  2. b) Watch steps

  3. c) Phone steps

Note

Daily Step Count Trend is a summarized data type. The update for summarized data type is not real-time. It takes about a minute, or in some cases it could take more time to update.

Figure 5 Expected Result of Today’s Step App

Figure 5 Expected Result of Today’s Step App