com.samsung.android.sdk.healthdata

Interface HealthConstants.StepDailyTrend

  • All Superinterfaces:
    HealthConstants.Common
    Enclosing class:
    HealthConstants


    public static interface HealthConstants.StepDailyTrend
    extends HealthConstants.Common
    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.
    Since:
    1.5.0
    • Field Detail

      • DAY_TIME

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

        • Mandatory
        • Type: long

        Since:
        1.5.0
        See Also:
        Constant Field Values
      • BINNING_DATA

        static final String 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.

        COUNT gives just a total step count. You can use this info to track more detailed step activity.

        • Optional
        • Type: byte[]

        It is ZIP compressed as the JSON format with the following keys.

        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:

        Since:
        1.5.0
        See Also:
        HealthDataUtil, Constant Field Values
      • CALORIE

        static final String CALORIE
        Total burned calories for daily steps in kilocalories.

        • Optional
        • Type: float

        Since:
        1.5.0
        See Also:
        Constant Field Values
      • DISTANCE

        static final String DISTANCE
        Total distance for daily steps in meters.

        • Optional
        • Type: float

        Since:
        1.5.0
        See Also:
        Constant Field Values
      • SOURCE_PKG_NAME

        static final String SOURCE_PKG_NAME
        Package name that provides step count data.

        If SOURCE_TYPE is SOURCE_TYPE_ALL or SOURCE_TYPE_PHONE_ONLY, this value is com.sec.android.app.shealth.

        • Optional
        • Type: String

        Since:
        1.5.0
        See Also:
        Constant Field Values
      • SOURCE_TYPE_ALL

        static final 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. 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.

        Since:
        1.5.0
        See Also:
        SOURCE_TYPE, Constant Field Values
      • SOURCE_TYPE_PARTNER_APP

        static final int SOURCE_TYPE_PARTNER_APP
        Each partner app.

        This source type data is created at the end of every day about 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.

        See SOURCE_PKG_NAME to find an wanted partner app.
        Since:
        1.5.0
        See Also:
        SOURCE_TYPE, Constant Field Values
      • SOURCE_TYPE_PHONE_ONLY

        static final int SOURCE_TYPE_PHONE_ONLY
        Phone only.
        This source type data is created at the end of every day about 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.
        Since:
        1.5.0
        See Also:
        SOURCE_TYPE, Constant Field Values
      • SPEED

        static final String SPEED
        Average speed of daily steps in meters per second.

        • Optional
        • Type: float

        Since:
        1.5.0
        See Also:
        Constant Field Values
      • HEALTH_DATA_TYPE

        static final String HEALTH_DATA_TYPE
        Data type name for step daily trend data.
        Use "com.samsung.shealth.step_daily_trend" to add permission to the manifest file.
        Since:
        1.5.0
        See Also:
        Constant Field Values