com.samsung.android.sdk.healthdata

Class HealthDataResolver.ReadRequest.Builder

  • java.lang.Object
    • com.samsung.android.sdk.healthdata.HealthDataResolver.ReadRequest.Builder
  • Enclosing interface:
    HealthDataResolver.ReadRequest


    public static class HealthDataResolver.ReadRequest.Builder
    extends Object
    This class is a builder to configure HealthDataResolver.ReadRequest.

       private HealthDataResolver.ReadRequest buildReadRequest(long startTime, long endTime) {
           HealthDataResolver.Filter filter =
                   HealthDataResolver.Filter.greaterThan(HealthConstants.Nutrition.CALORIE, 200);
      
           HealthDataResolver.ReadRequest request =
                   new HealthDataResolver.ReadRequest.Builder()
                   .setDataType(HealthConstants.Nutrition.HEALTH_DATA_TYPE)
                   .setLocalTimeRange(HealthConstants.Nutrition.START_TIME, HealthConstants.Nutrition.TIME_OFFSET,
                               startTime, endTime)
                   .setFilter(filter)
                   .build();
      
           return request;
       }

    Since:
    1.0.0
    • Method Detail

      • setDataType

        public HealthDataResolver.ReadRequest.Builder setDataType(String type)
        Sets a health data type for the request to read. It has to be specified before calling build().
        Parameters:
        type - HEALTH_DATA_TYPE of the data type
        Returns:
        The object that applies the health data type
        Since:
        1.0.0
      • setSourceDevices

        public HealthDataResolver.ReadRequest.Builder setSourceDevices(List<String> uuidList)
        Sets a UUID list for source devices to read health data.
        Parameters:
        uuidList - The UUID list for source devices
        Returns:
        The object that applies source devices
        Since:
        1.0.0
      • setProperties

        public HealthDataResolver.ReadRequest.Builder setProperties(String[] properties)
        Sets a property array for the health data result to read. If it is not specified, the health data result shows all properties of the data type.
        Parameters:
        properties - Properties that want to gain in the result
        Returns:
        The object that applies properties
        Since:
        1.0.0
      • setPropertyAlias

        public HealthDataResolver.ReadRequest.Builder setPropertyAlias(String property,
                                                                       String alias)
        Sets an alias for the given property.
        Parameters:
        property - The property to be shown with the alias
        alias - The alias for the property
        Returns:
        The object that applies the alias for the property
        Since:
        1.0.0
      • setPackageName

        public HealthDataResolver.ReadRequest.Builder setPackageName(String packageName)
        Sets the package name that provides health data to read.

        Accessory Data's Package Name

        Samsung Health collects the linked accessory's data also like Galaxy Watch.
        The accessory's data including Galaxy Watch is inserted to Samsung Health with the Samsung Health's package name, com.sec.android.app.shealth.
        If you want to read only the specific accessory's data, make a division the device ID.

        Parameters:
        packageName - The package name that provides health data
        Returns:
        The object that applies the package name
        Since:
        1.0.0
      • setResultCount

        public HealthDataResolver.ReadRequest.Builder setResultCount(int offset,
                                                                     int count)
        Sets the count range of result data with a given offset and count. If this method is not called, all result will be obtained from the result.

        If you want to get only 10 data from the 3rd position in the result, set offset as 2 and count as 10.

        Parameters:
        offset - The start position in the whole result, which equals to or is greater than 0
        count - The limited count of result, which is greater than 0
        Returns:
        The object that applies the range of the result
        Since:
        1.0.0
      • setTimeAfter

        public HealthDataResolver.ReadRequest.Builder setTimeAfter(long time)
        Sets the time range to retrieve result data which is inserted or updated to the health data store after the given time.
        It's different to set the time range based on the data's created or updated time to read data. If then, use:

        Moreover it is useful to check the health data store's change after your app reads the health data store's data at the last time.

        • If the data's source device is same with the current device, time means the inserted time that data is created on the current device.
        • If the data's source device is different, time indicates the synchronized time that data on other devices is synchronized to Samsung Health of the current device.

        Parameters:
        time - The time range to retrieve result data which is inserted or updated to the health data store after the specific time in milliseconds. Its value is started from January, 1, 1970 00:00:00 UTC.
        Returns:
        The object that applies the range of the result
        Since:
        1.0.0
      • setLocalTimeRange

        public HealthDataResolver.ReadRequest.Builder setLocalTimeRange(String timeProperty,
                                                                        String offsetProperty,
                                                                        long begin,
                                                                        long end)
        Sets the local time range not to miss data from the query's result when there exist data with a different TIME_OFFSET in the saved health data.

        The data that has a different TIME_OFFSET with other data's TIME_OFFSET can be saved when the daylight time is applied or the user moves to another region by like a travel. Building a complete query to read all data including the different TIME_OFFSET is not easy.
        Use this API to build a read request as possible.

        Parameters:
        timeProperty - The time property name that needs to add a filter
        offsetProperty - The time offset property
        begin - The beginning time with GMT+0 milliseconds.
        E.g. If you would like to get data from 00:00:00 on October 26th, 2021 in your region, set the value with 1635206400000.
        See sample codes.
        Its minimum value is Long.MIN_VALUE.
        end - The end time with GMT+0 milliseconds.
        E.g. If you would like to get data until 00:00:00 on October 26th, 2021 in your region, set the value with 1635206400000.
        See sample codes.
        Its maximum value is Long.MAX_VALUE.
        Returns:
        The object that applies the local time range
        Since:
        1.3.0