Development

Step 1: Open the app project

Open the given Android app project and find StepCountReporter.java.

The SDK library is samsung-health-data.jar in lib.


Step 2: Make a query to read step_daily_trend

The data type’s name and properties are:

com.samsung.shealth.step_daily_trend
Properties

Description

"day_time"

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

"source_type"

Kind of device sources.
* All sources: -2

In StepCountReporter.java, set a filter for:

  • "day_type": today
  • "source_type": all sources ("-2")
/*********************************************************************************
    * [Practice 1] Set a filter to get steps from all devices.
    *    - Fill below "TODO 1" with the source type's integer value for all devices
    ---------------------------------------------------------------------------------
    *    - (Hint) See the video tutorial and find "source_type" description.
    *********************************************************************************/
   // Create a filter for today's steps from all source devices
   Filter filter = Filter.and(
           Filter.eq("day_time", dayTime),
           Filter.eq("source_type", /*TODO 1*/));

Create a ReadRequest instance:

  • Data type name: "com.samsung.shealth.step_daily_trend"
  • Set a filter to the instance
/*********************************************************************************
    * [Practice 2] Build read request for today's all step.
    *    - Fill below "TODO 2" with the daily step count trend's data type name.
    ---------------------------------------------------------------------------------
    *    - (Hint) See the video tutorial and find the data type name.
    *********************************************************************************/
   HealthDataResolver.ReadRequest request = new ReadRequest.Builder()
               .setDataType("/*TODO 2*/")
               .setProperties(new String[] {"count", "binning_data"})
               .setFilter(filter)
               .build(); 

Step 3: Get today’s step count result

step_daily_trend has:

  • "count" property
com.samsung.shealth.step_daily_trend
Field

Description

"count"

Total number of daily steps.
* Type: int

A listener receives a query result. Check the result:

  • "count" of HealthData
try {
    resolver.read(request).setResultListener(result -> {
        try {
            Iterator<HealthData> iter = result.iterator();
            if (iter.hasNext()) {
                HealthData data = iter.next();
                int totalCount = data.getInt("count");
                byte[] binning = data.getBlob("binning_data");

                consumer.accept(new StepCountSummary(totalCount, getBinningCounts(binning)));
            }
        } finally {
            result.close();
        }
    });
} catch (Exception e) {
    Log.e(TAG, "Getting step count fails.", e);
}

The binning_data of step_daily_trend includes detailed step status every 10 minutes in a day.

com.samsung.shealth.step_daily_trend
Field

Description

"binning_data"

A set of step count data for every 10 minutes with the JSON format.
It provides maximum 144 data, 6 in an hour * 24 hours.
The "count" property gives just a total step count.
You can use this info to track more detailed step activity.
* Optional
* Type: byte[]

The binning_data is ZIP compressed as the JSON format with the following keys.

JSON key

Type

"count"

Int
"calorie"

Float
"distance"

Float
"speed"

Float

Run the app project and check the app dashboard on a phone.

  • Today’s total step
  • Graph’s step count in binning_data

You're done!

Congratulations! You have successfully achieved the goal of this Code Lab activity. Now, you can create a basic health dashboard app by yourself! But, if you're having trouble, you may check out the link below.

Basic Health Dashboard Complete Code377.27 KB