Measure skin temperature on Galaxy Watch
measure skin temperature on galaxy watch objective create a health app for galaxy watch, operating on wear os powered by samsung, utilizing samsung health sensor sdk to obtain skin temperature measurement results overview samsung health sensor 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 health sensor 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 148 0 kb connect your galaxy watch to wi-fi go to settings > connection > wi-fi and make sure that the wi-fi is enabled 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 on your watch, go to settings > about watch > software and tap on software version 5 times upon successful activation of developer mode, a toast message will display as on the image below afterwards, developer options will be visible under settings tap developer options and enable the following options adb debugging in developer options, search for 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 notethere may be differences in settings depending on your one ui version connect your galaxy watch to android studio go to settings > developer options > wireless debugging and choose pair new device take note of the wi-fi pairing code, ip address & port in android studio, go to terminal and type adb pair <ip address> <port> <wi-fi pairing code> when prompted, tap always allow from this computer to allow debugging 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 on your watch go to settings > apps > health platform quickly tap health platform title for 10 times this enables developer mode and displays [dev mode] below the title to stop using developer mode, quickly tap health platform title for 10 times to disable it start your project in 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_on_demand 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 healthtrackingservicehealthtrackingservice 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_on_demand type and assign it to the skintemperaturetracker object gethealthtracker with healthtrackertype skin_temperature_on_demand 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 healthtrackingservicehealthtrackingservice 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 health sensor sdk functionality * call gethealthtracker on healthtrackingservice object * use healthtrackertype skin_temperature_on_demand 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 healthtrackerhealthtracker 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 healthtrackerhealthtracker 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 datapointdatapoint 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 right click on com samsung health skintemptracking test and execute run 'tests in 'com samsung health skintemptrackin" command 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 once the app starts, allow the app to receive data from the body sensors 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 are having trouble, you may download this file skin temperature tracking complete project 147 8 kb to learn more about samsung health, visit developer samsung com/health