Measure skin temperature on Galaxy Watch with Samsung Privileged Health SDK


Objective

Create a health app for Galaxy Watch, operating on Wear OS powered by Samsung, utilizing Samsung Privileged Health SDK to obtain skin temperature measurement results.

Partnership Request

In this Code Lab, you will use a specially prepared mock library. It has limited functionality and uses dummy data instead of real-time data. You will need the full version of the Samsung Privileged Health SDK library to get real values, which is available to Samsung partners. Apply as a partner by checking out the Partner App Program for exclusive Samsung Privileged Health SDK access.

Overview

Samsung Privileged Health SDK provides means of accessing and tracking health information contained in the health data storage. Its tracking service gives raw and processed sensor data such as accelerometer and body composition data sent by the Samsung BioActive sensor. The Active sensor of Galaxy Watch runs powerful health sensors such as photoplethysmogram (PPG), electrocardiogram (ECG), bioelectrical impedance analysis (BIA), sweat loss, and SpO2.

See Samsung Privileged Health SDK descriptions for detailed information.

Set up your environment

You will need the following:

  • Galaxy Watch5 or newer with updated Health Platform
  • Android Studio (latest version recommended)
  • Java SE Development Kit (JDK) 17 or later

Sample Code

Here is a sample code for you to start coding in this Code Lab. Download it and start your learning experience!

Skin Temperature Tracking Sample Code
(123.64 KB)

Connect your Galaxy Watch to Wi-Fi

  1. Go to Settings > Connection > Wi-Fi and make sure that the Wi-Fi is enabled.

  2. From the list of available Wi-Fi networks, choose and connect to the same one as your PC.

Turn on Developer Mode and adjust its settings

  1. On your watch, go to Settings > About watch > Software and tap on Software version 5 times.

  2. Upon successful activation of Developer mode, a toast message will display as on the image below.

  3. Afterwards, Developer options will be visible under Settings.

  4. Tap Developer options and enable the following options:

    • ADB debugging

    • In Developer options find Wireless debugging

    • Turn on Wireless debugging

    • Check Always allow on this network and tap Allow

    • Go back to Developer options and click Turn off automatic Wi-Fi

Connect your Galaxy Watch to Android Studio

  1. Go to Settings > Developer options > Wireless debugging and choose Pair new device.

  2. Take note of the Wi-Fi pairing code, IP address & Port.

  3. In Android Studio, go to Terminal and type:

    adb pair <IP address>:<port> <Wi-Fi pairing code>
    
  4. When prompted, tap Always allow from this computer to allow debugging.

  5. After successfully pairing, type:

    adb connect <IP address of your watch>:<port>
    

    Upon successful connection, you will see the following message in Android Studio’s terminal:

    connected to <IP address of your watch>
    

    Now, you can run the app directly on your watch.

Turn on Developer Mode for Health Platform

This step is only applicable to registered partners of Samsung Privileged Health SDK. You can replace priv-health-tracking-mock-2023.aar in app > libs with the real library to receive real sensor data with the application. This requires Health Platform to be set in developer mode:

  1. On your watch go to Settings > Apps > Health Platform.

  2. Quickly tap Health Platform title for 10 times. This enables developer mode and displays [Dev mode] below the title.

  3. To stop using developer mode, quickly tap Health Platform title for 10 times to disable it.

Start your project

After downloading the sample code containing the project files, open your Android Studio and click Open to open an existing project.

Locate the downloaded Android project (SkinTempTracking) from the directory and click OK.

Check tracking capabilities

To track the data with the SDK, the device must support skin temperature, like the Galaxy Watch5. Skin temperature tracking can work in 2 modes: batching and on-demand. The tracker type for batching is HealthTrackerType.SKIN_TEMPERATURE_CONTINUOUS and HealthTrackerType.SKIN_TEMPERATURE for on-demand. In this Code Lab, you are going to use on-demand tracker.

In ConnectionManager.java, navigate to isSkinTemperatureAvailable() function. Use a provided HealthTrackingService object to create a HealthTrackerCapability instance, and send it to checkAvailableTrackers() function, and assign its result to availableTrackers list.

  • getTrackingCapability() returns a HealthTrackerCapability instance in HealthTrackingService object
HealthTrackingService

HealthTrackingService initiates a connection to Samsung's health tracking service and provides a HealthTracker instance to track a HealthTrackerType.

public HealthTrackerCapability

getTrackingCapability()

Provide a HealthTrackerCapability instance to get a supporting HealthTrackerType list.


/******************************************************************************************
 * [Practice 1] Check capabilities to confirm Skin Temperature availability
 *
 * ----------------------------------------------------------------------------------------
 *
 * (Hint) Replace TODO 1 with java code
 * Get HealthTrackerCapability object from HealthTrackingService
 * Send the object to checkAvailableTrackers()
 ******************************************************************************************/

boolean isSkinTemperatureAvailable(HealthTrackingService healthTrackingService) {
        if (healthTrackingService == null)
            return false;
        @SuppressWarnings("UnusedAssignment") List<HealthTrackerType> availableTrackers = null;

        //"TODO 1"

        if (availableTrackers == null)
            return false;
        else
            return availableTrackers.contains(HealthTrackerType.SKIN_TEMPERATURE);
    }
  

Initialization of skin temperature tracker

Before starting the measurement, initialize the skin temperature tracker by creating a HealthTracker object.

In SkinTemperatureListener.java, navigate to setSkinTemperatureTracker(). Using the provided HealthTrackingService object, create an instance of the HealthTracker class of SKIN_TEMPERATURE type and assign it to the skinTemperatureTracker object.

  • getHealthTracker() with HealthTrackerType.SKIN_TEMPERATURE as an argument creates a HealthTracker instance
  • After a single measurement, the tracker should be stopped when using on-demand measurement. For continuous measurement, use HealthTrackerType.SKIN_TEMPERATURE_CONTINUOUS
HealthTrackingService

HealthTrackingService initiates a connection to Samsung's health tracking service and provides a HealthTracker instance to track a HealthTrackerType.

HealthTracker

getHealthTracker(HealthTrackerType healthTrackerType)

Create a HealthTracker instance for the given healthTrackerType.

/*******************************************************************************************
 * [Practice 2] Setup Skin Temperature tracker
 *
 * ----------------------------------------------------------------------------------------
 *
 * (Hint) Replace TODO 2 with java code
 * Initialize skinTemperatureTracker with proper Samsung Privileged Health SDK functionality
 * Call getHealthTracker() on HealthTrackingService object
 * Use HealthTrackerType.SKIN_TEMPERATURE as an argument
 ******************************************************************************************/
void setSkinTemperatureTracker(HealthTrackingService healthTrackingService) {
    //"TODO 2"
}

Starting and stopping the tracker

For the client app to obtain the data through the SDK, set a listener method on HealthTracker. This method is called every time there is new data.

HealthTracker

HealthTracker enables an application to set an event listener and get tracking data for a specific HealthTrackerType.

public void

setEventListener(HealthTracker.TrackerEventListener listener)

Set an event listener to the HealthTracker instance.

void startTracker() {
    if (!isHandlerRunning) {
        skinTemperatureHandler.post(() -> skinTemperatureTracker.setEventListener(skinTemperatureListener));
        isHandlerRunning = true;
    }
}

After the finished measurement, the on-demand tracker should be stopped. You can do that by unsetting the event listener from HealthTracker.

HealthTracker

HealthTracker enables an application to set an event listener and get tracking data for a specific HealthTrackerType.

public void

unsetEventListener()

Stop the registered event listener to this HealthTracker instance.

void stopTracker() {
    if (skinTemperatureTracker != null)
        skinTemperatureTracker.unsetEventListener();
    skinTemperatureHandler.removeCallbacksAndMessages(null);
    isHandlerRunning = false;
}

Process obtained skin temperature data

The answer from the HealthTrackingService is asynchronous. The SkinTemperatureListener receives the callback containing a data point with all the required information. Follow the steps below to get skin temperature data:

In SkinTemperatureListener.java, go to the updateSkinTemperature() function and read skin temperature data from DataPoint:

  • Get skin temperature status using DataPoint API (key: ValueKey.SkinTemperatureSet.STATUS).
  • Get skin temperature value using DataPoint API (key: ValueKey.SkinTemperatureSet.OBJECT_TEMPERATURE).
  • Get ambient temperature value using DataPoint API (key: ValueKey.SkinTemperatureSet.AMBIENT_TEMPERATURE)
DataPoint

DataPoint provides a map of ValueKey and Value with a timestamp.

public <T>T

getValue(ValueKey<T>type)

Get data value for the given key.

private final HealthTracker.TrackerEventListener skinTemperatureListener = new HealthTracker.TrackerEventListener() {
    @Override
    public void onDataReceived(@NonNull List<DataPoint> list) {
        stopTracker();
        for (DataPoint data : list) {
            updateSkinTemperature(data);
        }
    }

 };

/*******************************************************************************************
 * [Practice 3] Read values from DataPoint object
 *  - Get skin temperature status value
 *  - Get wrist skin temperature value - it's named "OBJECT_TEMPERATURE" in the library
 *  - Get ambient temperature value
 -------------------------------------------------------------------------------------------
 *  - (Hint) Replace TODO 3 with parts of code
 *      (1) remove SkinTemperatureStatus.INVALID_MEASUREMENT and
 *          set status from 'dataPoint' object using data.getValue(ValueKey.SkinTemperatureSet.STATUS)
 *
 *      If status is 'SkinTemperatureStatus.SUCCESSFUL_MEASUREMENT' then:
 *      (2) set wristSkinTemperatureValue from 'dataPoint' object using:
 *              data.getValue(ValueKey.SkinTemperatureSet.OBJECT_TEMPERATURE);
 *      (3) set ambientTemperatureValue from 'dataPoint' object using:
 *              data.getValue(ValueKey.SkinTemperatureSet.AMBIENT_TEMPERATURE);
 ******************************************************************************************/
void updateSkinTemperature(DataPoint data) {
    final int status = SkinTemperatureStatus.INVALID_MEASUREMENT;
    float wristSkinTemperatureValue = 0;
    float ambientTemperatureValue = 0;

    //"TODO 3"

    trackerDataSubject.notifySkinTemperatureTrackerObservers(status, ambientTemperatureValue, wristSkinTemperatureValue);
}

Run unit tests

For your convenience, you will find an additional Unit Tests package. This will let you verify your code changes even without using a physical watch. See the instruction below on how to run unit tests:

  1. Right click on com.samsung.health.skintemptracking (test) and execute Run 'Tests in 'com.samsung.health.skintemptrackin" command.

  1. If you have completed all the tasks correctly, you can see all the unit tests pass successfully.

Run the app

After building the APK, you can run the application on a connected device to measure your skin temperature.

  1. Once the app starts, allow the app to receive data from the body sensors.

  1. Afterwards, the screen shows the application. Tap the Measure button to get your skin temperature. To stop measuring, tap on the Stop button.

You're done!

Congratulations! You have successfully achieved the goal of this Code Lab. Now, you can create a health app that measures skin temperature by yourself! If you face any trouble, you may download this file:

Skin Temperature Tracking Complete Project
(123.09 KB)

To learn more about Samsung Health, visit:
developer.samsung.com/health