Filter
-
Content Type
-
Category
Mobile/Wearable
Visual Display
Digital Appliance
Platform
Recommendations
Filter
FAQ health
docfaq faq search form search what are the main features of the samsung health accessory sdk? the samsung health accessory sdk defines bluetooth low energy ble compatible guidelines and samsung health specifications based on bluetooth generic attributes gatt , including service structure, to connect with samsung health ble compatible guidelines include data communication flows defined in ble standard specifications required by samsung health through a wide variety of compatible health devices, users can sync data related to blood glucose levels, blood pressure, heart rate, weight, temperature, cycling power, and cycling speed and cadence with samsung health additionally, samsung health provides data flows and specifications for upcoming supported services, including pedometers and exercise and sleep monitors, which are not covered in standard ble specs these standards are set forth in a similar structure to ble standard specs, allowing device vendors to easily adapt to the specifications health#accessory sdk#ble how do i get access to the samsung health accessory sdk and documentation? you can access the samsung health accessory sdk and documentation here health#accessory sdk#guidelines are the samsung health specifications defined by accessory sdk compatible with standard ble bluetooth low energy ? samsung health specifications defined by accessory sdk are based on the bluetooth® specifications, but there are some differences, so see here for details health#accessory sdk#ble#health specifications#bluetooth low energy how do i check if a device complies with sdk specifications? to ensure compliance with samsung health specifications, we have developed the samsung health compliance verification tool this tool allows developers to 1 validate device behavior against samsung health requirements such as data format and protocol adherence , 2 diagnose implementation gaps through automated test reports and error logs by integrating this tool into your development workflow, you can proactively identify and resolve compatibility issues, ensuring seamless interoperability with the samsung health ecosystem more information about the verification tool is available here health#accessory sdk#verification tool how do i use the verification tool? to verify your device with the verification tool vt , refer to the vt user guide for detailed implementation procedures more information about the vt user guide is available here health#accessory sdk#verification tool what are the main features of the smartthings support specification? samsung health is an application to provide insight through various health indicators and acquire health information from health devices smartthings is an application to help user to connect, monitor, and control multiple smart home devices samsung health devices can quickly and easily be onboarded on smartthings after onboarding, samsung health can connect to the device automatically for use the smartthings support specification provides samsung health guidelines for health devices to support the interworking between samsung health and smartthings it includes the recommended specification and communication flow health#accessory sdk#smartthings support specification how do i get access to the smartthings support specification and documentation? you can access smartthings support specification refer to here health#accessory sdk#smartthings support specification#smartthings is support required for the pop-up and qr code scanning onboarding methods? no, these methods are optional they are intended to provide users with a more convenient onboarding experience health#accessory sdk#smartthings support specification#pop-up#qr code what is the relationship between smartthings support specification and accessory sdk? the smartthings support specification focuses on device onboarding, enabling devices to be scanned, registered, and managed within the st, after which device information can be synchronized to the health application the accessory sdk, on the other hand, defines data interaction protocols between devices and the health application, standardizing data formats such as sensor readings and commands and facilitating real-time communication together, they ensure device-to-device functionality the smartthings support specification handles device management, while the accessory sdk governs post-connection data flow developers must integrate both sdks to achieve seamless device integration and reliable data exchange health#accessory sdk#smartthings support specification#accessory sdk is onboarding for health devices limited to the smartthings platform? yes, all future health devices will only support onboarding through the st platform this is intended to provide a unified user experience without requiring users to distinguish between health devices and other categories of equipment health#accessory sdk#smartthings support specification#onboarding#limitation
Develop Health
apioverviewpackageclasstreedeprecatedindex com samsung android sdk healthdata class healthdataobserver java lang object com samsung android sdk healthdata healthdataobserver public abstract class healthdataobserver extends object this class defines a health data observer for health data change adding an observer you can add an observer for the specific health data type and get notification in onchange string if the designated health data is changed in case that you add an observer for the data type that updates too frequently in short time like step count, it can send too many events to your application and it can bring degradation of your application's performance check that your application needs to update data with real-time from samsung health again before adding an observer a health data observer can be defined as below public class healthdataobserverexample { // the state of connection private healthdatastore mstore; public static final string app_tag = "myapp"; private final healthdataobserver mobserver = new healthdataobserver null { // checks notification for changed health data @override public void onchange string datatypename { log d app_tag, "health data is changed " ; readchangeddata datatypename ; } }; when you add an observer for the specific health data type, specify the data type name as below only data type is allowed to be observed public void start { // adds an observer for change of the weight healthdataobserver addobserver mstore, healthconstants weight health_data_type, mobserver ; } the change notification is received in onchange string and you can check updated health data as below private void readchangeddata string datatypename { healthdataresolver resolver = new healthdataresolver mstore, null ; healthdataresolver readrequest rdrequest = new healthdataresolver readrequest builder setdatatype datatypename build ; try { // make an asynchronous request to read health data resolver read rdrequest setresultlistener mrdlistener ; } catch exception e { log d app_tag, "healthdataresolver read fails " ; } } private final healthresultholder resultlistener<healthdataresolver readresult> mrdlistener = new healthresultholder resultlistener<healthdataresolver readresult> { @override public void onresult healthdataresolver readresult result { try { iterator<healthdata> iterator = result iterator ; if iterator hasnext { healthdata data = iterator next ; // check the result } } finally { result close ; } } }; } since 1 0 0 constructor summary constructors constructor and description healthdataobserver handler handler creates a healthdataobserver instance method summary all methods static methods instance methods abstract methods concrete methods modifier and type method and description static void addobserver healthdatastore store, string datatypename, healthdataobserver observer adds an observer that wants to follow data change for the given health data type abstract void onchange string datatypename called if health data registered as an observer is changed static void removeobserver healthdatastore store, healthdataobserver observer removes a registered observer constructor detail healthdataobserver public healthdataobserver handler handler creates a healthdataobserver instance parameters handler - the handler to run onchange string if it's null, onchange string event is run on binder thread which is invoked by samsung health since 1 0 0 method detail onchange public abstract void onchange string datatypename called if health data registered as an observer is changed parameters datatypename - the data type name that health data is changed since 1 0 0 addobserver public static void addobserver healthdatastore store, string datatypename, healthdataobserver observer adds an observer that wants to follow data change for the given health data type parameters store - the health data store for connection datatypename - the health data type name to follow change observer - an observer to receive notification if health data is changed throws illegalargumentexception - if the data type or observer is invalid illegalstateexception - if the instance of health data store is invalid or a remote-invocation error occurs in the connection since 1 0 0 removeobserver public static void removeobserver healthdatastore store, healthdataobserver observer removes a registered observer parameters store - health data store for connection observer - the added observer throws illegalargumentexception - if the observer is invalid illegalstateexception - if the instance of health data store is invalid or a remote-invocation error occurs in the connection since 1 0 0
Develop Health
apioverviewpackageclasstreedeprecatedindex samsung health sdk for android - data api reference 1 5 1 health data this document describes com samsung android sdk healthdata apis in samsung health sdk for android see description packages package description com samsung android sdk healthdata this package provides classes and interfaces for the health data framework in samsung health sdk for android health data this document describes com samsung android sdk healthdata apis in samsung health sdk for android the health data package contains classes and interfaces which enable you to create applications with the following functionalities health data store a partner app that uses samsung health sdk for android can write its health data to samsung health or read samsung health's data through the health data store connection see health data store for more information health data type the sdk provides useful predefined and custom data types see health data types for more information privacy data permission acquisition is required to access a specific data type see permission manager for more information for more information related to the development environment, fundamentals, features and sample descriptions, see programming guide compatible version of samsung health samsung health sdk for android works with samsung health the sdk's data library works properly with the specific samsung health version sdk's heath data library version samsung health compatible version 1 5 1 6 28 or above 1 5 0 6 12 or above 1 4 0 6 2 or above 1 3 0 5 11 or above 1 2 0 5 10 or above 1 0 0 4 0 or above e g if you create your app with the health data library 1 5 0, it requires to install samsung health 6 12 or above in the device if the sdk and samsung health's version is not matched, the sdk gives an error old_version_platform you can resolve the error simply and induce the users to update samsung health to the latest version here is a guide to prevent the related error connect to the health data store see healthdatastore connectservice private healthdatastore mstore; @override public void oncreate bundle savedinstancestate { // create a healthdatastore instance and set its listener mstore = new healthdatastore this, mconnectionlistener ; // request the connection to the health data store mstore connectservice ; } if it fails, check healthconnectionerrorresult onconnectionfailed private final healthdatastore connectionlistener mconnectionlistener = new healthdatastore connectionlistener { // @override public void onconnectionfailed healthconnectionerrorresult error { // } if the error is old_version_platform, it means that samsung health needs to be updated to the latest version show a proper message to the user @override public void onconnectionfailed healthconnectionerrorresult error { if error geterrorcode == healthconnectionerrorresult old_version_platform { // show a message to the user to update samsung health } } check a resolution for the error with healthconnectionerrorresult hasresolution if it gives true, resolve the error with healthconnectionerrorresult resolve if error hasresolution { // if there is a solution, resolve it error resolve mainactivity this ; } the samsung health platform leads to upgrade samsung health on the app market see its example exception handing
Develop Health
dochow to implement the sweat loss monitor application the following flow chart represents the order of invocation of the health services main functions and the health tracking service ones, and the interaction between both the libraries the following image represents an overview of the main classes used in the sweat loss example application the sweatingbucketsservice is a foreground service, which controls both healthservicesmanager and trackingservicemanager it starts when the user presses the start button and it stops after user stops the exercise, and gets the final sweat loss value when the user destroys the activity by swiping right during the active exercise, the application will continue to work in the background in the foreground service the user knows about the running application from the notification when the user opens the application again either via notification or by tapping the application icon , the new activity will show the current exercise status a similar event occurs when the application goes to the background i e when the screen goes into the sleep mode in this case, the activity is not destroyed, only get onstop event the user can bring the activity back by tapping the notification to observe the current exercise status and, after tapping the stop button, to get the final sweat loss result sweatingbucketsservice is responsible for collecting the results from the health services and the health tracking service and exchanging the data between both the services it also reports the following status values to the ui status for sweat loss measurement sweat loss value exercise distance exercise duration average steps per minute current steps per minute connection errors not available capabilities it uses android's messenger mechanism to establish a two-way communication with the ui permissions in order to measure the sweat loss, we need to get the following permissions body_sensors to use the samsung health sensor sdk’s sweat loss tracker activity_recognition for measuring the steps per minute during a running exercise additionally, we also need foreground_service to be able to continue measurement in the background internet to resolve the samsung health sensor sdk’s healthtrackingservice connection error the application will display the permissions popup immediately after the start capabilities before using the health services and the samsung health sensor sdk’s apis, let us check whether the galaxy watch can measure the sweat loss we need to check availability of the following capabilities from health services exercisetype running datatype steps_per_minute datatype distance from samsung health sensor sdk healthtrackertype sweat_loss all the capabilities from both the services should be checked immediately after the application launch so that the user is informed, as soon as possible, about any problems capabilities check with health services health services is used to measure a running exercise in order to check the capabilities of the running exercise measurement with health services, we first need to obtain the exerciseclient object exerciseclient = healthservices getclient context getexerciseclient ; we need to check the capabilities of the running exercise type, steps_per_minute and distance the capabilities come asynchronously public static void checkcapabilities exerciseclient exerciseclient, healthservicescapabilitieseventlistener listener { futures addcallback exerciseclient getcapabilitiesasync , new futurecallback<exercisecapabilities> { @override public void onsuccess exercisecapabilities result { log i tag, "setexercisecapabilities onsuccess " ; final boolean runningcapabilityavailable = result getsupportedexercisetypes contains exercisetype running ; final boolean stepsperminutecapabilityavailable = result getexercisetypecapabilities exercisetype running getsupporteddatatypes contains steps_per_minute ; final boolean distancecapabilityavailable = result getexercisetypecapabilities exercisetype running getsupporteddatatypes contains datatype distance ; listener onhealthservicescapabilitiesavailabilityresult runningcapabilityavailable && stepsperminutecapabilityavailable, distancecapabilityavailable ; } @override public void onfailure @nonnull throwable t { log i tag, "setexercisecapabilities onfailure , throwable message " + t getmessage ; } }, executors newsinglethreadexecutor ; } the onhealthservicescapabilitiesavailabilityresult listener informs the viewmodel about the results of the capabilities check capabilities check with health tracking service sweat loss is measured with the samsung health sensor sdk after a running exercise if the version of the galaxy watch’s software or the samsung health sensor sdk’s library is old, measuring sweat loss may not be available therefore, checking the capabilities of samsung health sensor sdk is required before starting the measurement first, get the healthtrackingservice object and set a connection listener to connect to the samsung health sensor sdk’s health tracking service healthtrackingservice = new healthtrackingservice healthtrackingserviceconnectionlistener, myapp getappcontext ; the connection listener will be covered in the following sections after connecting to the tracking service, we can check the capabilities this time it is a synchronous call public static boolean hascapabilities context context { if healthtrackingserviceconnection getinstance context isconnected { final list<healthtrackertype> availabletrackers = healthtrackingserviceconnection getinstance context gethealthtrackingservice gettrackingcapability getsupporthealthtrackertypes ; if availabletrackers contains healthtrackertype sweat_loss { log i tag, "the system does support sweat loss tracking" ; return true; } } log e tag, "the system does not support sweat loss tracking" ; return false; } if any of the mandatory capabilities are not available, the application cannot work correctly we should display a failure message to the user setting up and starting the exercise when the user starts the exercise, he taps the start button the request goes to the sweatingbucketsservice, which in turn requests the healthservicesmanager to start the exercise we need to configure the exercise to provide us with the steps per minute and distance using exerciseconfig setting the exercise type exercisetype running setting interesting data types for a running exercise datatype steps_per_minute and datatype distance then, invoke exerciseclient startexerciseasync the implementation of the process looks like this protected void startexercise throws runtimeexception { final exerciseconfig builder exerciseconfigbuilder = exerciseconfig builder exercisetype running setdatatypes new hashset<> arrays aslist datatype distance, steps_per_minute setisautopauseandresumeenabled false setisgpsenabled false ; log i tag, "calling startexerciseasync" ; futures addcallback exerciseclient startexerciseasync exerciseconfigbuilder build , new futurecallback<void> { @override public void onsuccess @nullable void result { log i tag, "startexerciseasync onsuccess " ; } @override public void onfailure @nonnull throwable t { log i tag, "startexerciseasync onfailure starting exercise " + t getmessage ; healthserviceseventlistener onexerciseerror r string exercise_starting_error ; } }, executors newsinglethreadexecutor ; } we show the distance on the watch’s screen and the steps per minute data are sent to the healthtracker object for further processing more on this in below sections steps per minute is an instantaneous value, which is fine when we pass it to the healthtracker, as it expects such format however, we should process it to display the preferred average value to the user the distance value received indicates the distance between the current and the previous readings to display the distance value to the user, we first need to sum all the values from the beginning of the exercise subscribing to updated exercise data health services enables a watch application to receive the running exercise’s data update and to manage the exercise’s lifetime we obtained the exerciseclient in capabilities check now, we set update callback to receive the exercise results including steps per minute and distance exerciseclient setupdatecallback exerciseupdatecallback ; in the callback, we receive the updated exercise state information and the latest exercise data private final exerciseupdatecallback = new exerciseupdatecallback { @override public void onexerciseupdatereceived exerciseupdate update { log i tag, "exerciseupdate update " + update ; exercisestate = update getexercisestateinfo getstate ; log i tag, "exercise state " + exercisestate ; if exercisestate == exercisestate active { if !wasexerciseactive { healthserviceseventlistener onexercisebecomeactive ; } } else { wasexerciseactive = false; if exercisestate == exercisestate ended { switch update getexercisestateinfo getendreason { case exerciseendreason user_end healthserviceseventlistener onexerciseuserended ; break; case exerciseendreason auto_end_superseded log i tag, "exercise terminated it was superseded by other exercise, started by other client " ; healthserviceseventlistener onexerciseautoended r string error_exercise_terminated ; break; case exerciseendreason auto_end_permission_lost log i tag, "exercise permission lost " ; healthserviceseventlistener onexerciseautoended r string error_exercise_permission_lost ; break; } } } wasexerciseactive = exercisestate == exercisestate active; updateintervaldatapoints update getlatestmetrics getintervaldatapoints ; updatesampledatapoints update getlatestmetrics getsampledatapoints ; } }; the detailed exercise state is returned with the update callback as update getexercisestateinfo getstate ; we can start tracking when the state becomes active and stop tracking when it becomes ended the ended status can have several reasons available in update getexercisestateinfo getendreason user_end the exercise ended by the user auto_end_superseded the exercise object has been superseded by another application auto_end_permission_lost the permission has been revoked by the user we should display an error message when the reason is not user_end the exercise results updates are typically received every second, but when the application goes to the background after a couple of seconds, the battery saving mechanism is activated, resulting in the data being updated every 150 secs, i e 2 5 min the results' resolution remains the same, but the data come in batches in the example, the application data is sent to the sweatingbucketsservice via callbacks ondistancedatareceived, onstepsperminutedatareceived the data is sent immediately to the health tracking service connecting to the health tracking service first, connect to the health tracking service private static final connectionlistener connectionlistener = new connectionlistener { @override public void onconnectionsuccess { log i tag, "connection to healthtrackingservice succeeded " ; connected = true; healthtrackingserviceconnectionlistener onhealthtrackingserviceconnectionresult true ; } @override public void onconnectionended { log i tag, "connection to healthtrackingservice ended " ; connected = false; } @override public void onconnectionfailed healthtrackerexception e { connected = false; log i tag, "connection to healthtrackingservice failed error message " + e getmessage ; if e hasresolution { healthtrackingserviceconnectionlistener onhealthtrackingserviceconnectionerrorwithresolution e ; } else { healthtrackingserviceconnectionlistener onhealthtrackingserviceconnectionresult false ; } } }; private static void inithealthtrackingservice { if healthtrackingservice == null { healthtrackingservice = new healthtrackingservice connectionlistener, myapp getappcontext ; } } we are informing the sweatlossviewmodel about the result using callback with onhealthtrackingserviceconnectionresult boolean result in the sweat loss monitor application the samsung health sensor sdk provides apis to resolve connection exceptions if the watch’s health platform is not installed, or its version is old to run the sdk’s library in the error cases, we can check the error’s resolution and resolve them by calling the sdk’s healthtrackerexception hasresolution and healthtrackerexception resolve to check the error’s resolution, the internet permission is required resolving the exception entails being redirected to a view, which downloads the health platform application on the watch setting an event listener to get a sweat loss result once we connect, it is time to acquire the healthtracker object to use the sweat loss feature try { sweatlosstracker = healthtrackingserviceconnection getinstance context gethealthtrackingservice gethealthtracker healthtrackertype sweat_loss, new userprofile gettrackeruserprofile , com samsung android service health tracking data exercisetype running ; } catch final illegalargumentexception e { log i tag, "tracker not created, an exception " + e getmessage ; } the sweat loss amount varies depending on the user’s height, weight, age, and gender set the user profile information with the userprofile object we can define the trackeruserprofile as public class userprofile { public trackeruserprofile gettrackeruserprofile { // the following user profile values are needed for sweat loss calculations // in the real market-ready application the numbers should be editable in ui // height in cm final float height = 182f; // weight in kg final float weight = 80f; // gender 0 woman, 1 man final int gender = 1; final int age = 45; final trackeruserprofile builder builder = new trackeruserprofile builder ; builder setheight height ; builder setweight weight ; builder setgender gender ; builder setage age ; return builder build ; } } to get the sweat loss result, set a trackereventlistener private final healthtracker trackereventlistener trackereventlistener = new healthtracker trackereventlistener { @override public void ondatareceived @nonnull list<datapoint> list { log i tag, "ondatareceived invoked " ; final valuekey<float> sweatlossvaluekey = valuekey sweatlossset sweat_loss; final valuekey<integer> statusvaluekey = valuekey sweatlossset status; // there is always up to 1 element in the list if !list isempty { log i tag, "ondatareceived list size is " + list size + ", timestamp " + list get 0 gettimestamp ; final float sweatloss = list get 0 getvalue sweatlossvaluekey ; final int status = list get 0 getvalue statusvaluekey ; sweatlossstatus = status; sweatlossvalue = sweatloss; log i tag, "sweat loss " + sweatloss + " status " + status ; final boolean finalresult = finalresult status, sweatloss ; //unset listener right after getting final result if finalresult unsettrackerupdatelistener ; trackingserviceeventlistener onsweatlossdatareceived status, sweatloss, finalresult ; } else { log i tag, "ondatareceived list size is null" ; } } @override public void onflushcompleted { log i tag, " onflushcompleted called" ; } @override public void onerror healthtracker trackererror trackererror { if trackererror == healthtracker trackererror permission_error { trackingserviceeventlistener onhealthtrackererror r string tracker_error_permission_error ; } if trackererror == healthtracker trackererror sdk_policy_error { trackingserviceeventlistener onhealthtrackererror r string tracker_error_sdk_policy_denied ; } } }; start an exercise and setting the exercise’s state to start when the user taps the start button on the sweat loss monitor application, we start the exercise in health services by calling startexerciseasync when the exercise starts, we should set the sweatlosstracker’s exercise state to start sweatlosstracker setexercisestate exercisestate start ; during the exercise, the watch’s related sensors measure the exercise and health services updates the exercise’s steps per minute and distance in the background the updated steps per minute must be sent to the sweat loss healthtracker with healthtracker setexercisedata public void feedtrackerwithstepsperminutedata float[] stepsperminutevalues, long[] stepsperminutetimestamps { log i tag, "feedtrackerwithstepsperminutedata " ; final datatype steps_per_minute = datatype step_per_minute; try { log i tag, "feed tracker with stepsperminute data " + arrays tostring stepsperminutevalues ; sweatlosstracker setexercisedata steps_per_minute, stepsperminutevalues, stepsperminutetimestamps ; } catch final illegalargumentexception e { log i tag, " error data spm " + arrays tostring stepsperminutevalues + " utctime " + stepsperminutetimestamps[0] ; } catch final illegalstateexception e { log i tag, e getmessage ; } } get a sweat loss measurement result after the exercise when the user taps the stop button on the sweat loss monitor application to end the exercise, stop the exercise with health services as follows invoke exerciseclient stopexerciseasync wait until the status of the exercise read in update callback changes to ended inform the healthtracker about the stopped exercise to set the sweat loss healthtracker’s exercise state to stop, just invoke sweatlosstracker setexercisestate exercisestate stop ; it gives the final sweat loss measurement result through trackereventlistener that we have set in setting an event listener to get a sweat loss result the result includes the sweat loss amount and the sweat loss measurement result’s status flag see the samsung health sensor sdk’s api reference document for the sweat loss status details unset the sweat loss event listener after receiving the sweat loss result, unset the sweat loss healthtracker’s event listener sweatlosstracker unseteventlistener ; after unsetting the update listener, the watch’s sensors used by healthtracker will stop working
Develop Health
docsamsung health accessory sdk samsung health provides a feature that allows users to discover compatible health devices many health devices are bluetooth enabled and this is the primary method of interfacing with samsung health the samsung health accessory sdk defines bluetooth low energy ble compatible guidelines and samsung health specifications based on bluetooth generic attributes gatt , including service structure, to connect with samsung health ble compatible guidelines include the data communication flows defined in ble standard specs that samsung health requires through a wide variety of compatible health devices, users can sync data related to blood glucose levels, blood pressure, heart rate, weight, cycling power and cadence with samsung health additionally, samsung health provides data flows and specifications for forthcoming supported services including pedometers and exercise and sleep monitors, which are not covered in standard ble specs these standards are set forth in a familiar structure to standard ble standard specs, allowing device vendors to easily adapt to the specifications samsung health provides an easy interface to connect ble health devices as well as manage health data from these health devices users will be able to measure and record their health history and enhance their experience by taking advantage of the many services provided through samsung health upon approval, partners can use the “works with samsung health” seal on their devices or packaging
Learn Code Lab
codelabmeasure blood oxygen level and heart rate on galaxy watch objective create a health app for galaxy watch, operating on wear os powered by samsung, utilizing samsung health sensor sdk to trigger and obtain results of simultaneous blood oxygen level spo2 and heart rate measurements 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 latest bioactive 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 watch4 or newer android studio latest version recommended java se development kit jdk 11 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! measuring blood oxygen level and heart rate sample code 159 2 kb connect your galaxy watch to wi-fi go to settings > connection > wi-fi and make sure that 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 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 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, click open to open existing project locate the downloaded android project from the directory and click ok establish service connection and check capabilities for the device to track data with the samsung health sensor sdk, it must connect to the service by healthtrackingservice api after establishing a connection, verify if the required tracker type is available to check this, get the list of available tracker types and verify that the tracker is on the list in this code lab, you will utilize blood oxygen level and heart rate trackers the healthtrackingservice api usage is in the table below healthtrackingservicehealthtrackingservice initiates a connection to samsung's health tracking service and provides a healthtracker instance to track a healthtrackertype public void connectservice establish a connection with samsung's health tracking service public void disconnectservice release a connection for samsung's health tracking service public healthtrackercapability gettrackingcapability provide a healthtrackercapability instance to get a supporting health tracker type list initialize multiple trackers before the measurement starts, initialize the spo2 tracker by obtaining the proper health tracker object in the connectionmanager java file, navigate to initspo2 , create an oxygen saturation healthtracker instance, and pass it to the spo2listener instance get the healthtracker object using the healthtrackingservice api use the healthtrackertype spo2_on_demand type as parameter healthtrackingservicehealthtrackingservice initiates a connection to samsung's health tracking service and provides a healthtracker instance to track a healthtrackertype public healthtracker gethealthtracker healthtrackertype healthtrackertype provide a healthtracker instance for the given healthtrackertype pass the healthtracker object to the spo2listener instance object spo2listener public void sethealthtracker healthtracker tracker set healthtracker instance for the given tracker /******************************************************************************************* * [practice 1] create blood oxygen level health tracker object * - get health tracker object * - pass it to spo2listener ------------------------------------------------------------------------------------------- * - hint replace todo 1 with parts of code * 1 get healthtracker object using healthtrackingservice gethealthtracker * use healthtrackertype spo2_on_demand type as parameter * 2 pass it to spo2listener using sethealthtracker function ******************************************************************************************/ public void initspo2 spo2listener spo2listener { //"todo 1 1 " //"todo 1 2 " sethandlerforbaselistener spo2listener ; } next, in the connectionmanager java file, in the initheartrate function, create a heart rate healthtracker instance, and pass it to the heartratelistener instance get the healthtracker object using the healthtrackingservice api use the healthtrackertype heart_rate_continuous type as parameter pass the healthtracker object to the heartratelistener instance object heartratelistener public void sethealthtracker healthtracker tracker set healthtracker instance for the given tracker /******************************************************************************************* * [practice 2] create heart rate health tracker object * - get health tracker object * - pass it to heartratelistener ------------------------------------------------------------------------------------------- * - hint replace todo 2 with parts of code * 1 get healthtracker object using healthtrackingservice gethealthtracker * use healthtrackertype heart_rate_continuous type as parameter * 2 pass it to heartratelistener using sethealthtracker function ******************************************************************************************/ public void initheartrate heartratelistener heartratelistener { //"todo 2 1 " //"todo 2 2 " sethandlerforbaselistener heartratelistener ; } start and stop trackers for the client app to start obtaining the data through the sdk, set a listener method on healthtracker this method will be called every time there is new data after the measurement completes, the listener has to be disconnected to start measurement in the baselistener java file, navigate to starttracker function, and set trackereventlistener as listener healthtracker object set an event listener on healthtracker object using healthtracking api use the healthtracker trackereventlistener object instance as parameter 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 this healthtracker instance /******************************************************************************************* * [practice 3] start health tracker by setting event listener * - set event listener on health tracker ------------------------------------------------------------------------------------------- * - hint replace todo 3 with parts of code * set event listener on healthtracker object using healthtracker seteventlistener * use trackereventlistener object as parameter ******************************************************************************************/ public void starttracker { log i app_tag, "starttracker called " ; log d app_tag, "healthtracker " + healthtracker tostring ; log d app_tag, "trackereventlistener " + trackereventlistener tostring ; if !ishandlerrunning { handler post -> { //"todo 3" sethandlerrunning true ; } ; } } to stop measurement, unset the trackereventlistener from the healthtracker object in the stoptracker function unset the event listener on healthtracker object using healthtracking api 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 /******************************************************************************************* * [practice 4] stop health tracker by removing event listener * - unset event listener on health tracker ------------------------------------------------------------------------------------------- * - hint replace todo 4 with parts of code * unset event listener on healthtracker object using healthtracker unseteventlistener ******************************************************************************************/ public void stoptracker { log i app_tag, "stoptracker called " ; log d app_tag, "healthtracker " + healthtracker tostring ; log d app_tag, "trackereventlistener " + trackereventlistener tostring ; if ishandlerrunning { //"todo 4" sethandlerrunning false ; handler removecallbacksandmessages null ; } } process obtained and batching data the response from the platform will be asynchronous with the results you want to obtain follow the steps below to get blood oxygen level and heart rate data in the spo2listener java file, navigate to updatespo2 function, and read spo2 data from datapoint get the oxygen saturation status using the datapoint api key valuekey spo2set status get the oxygen saturation value using the datapoint api key valuekey spo2set spo2 datapointdatapoint provides a map of valuekeyand value with a timestamp public <t>t getvalue valuekey<t> type get data value for the given key /******************************************************************************************* * [practice 5] read values from datapoint object * - get blood oxygen level status * - get blood oxygen level value ------------------------------------------------------------------------------------------- * - hint replace todo 5 with parts of code * 1 remove spo2status calculating and * set status from 'datapoint' object using datapoint getvalue valuekey spo2set status * 2 set spo2value from 'datapoint' object using datapoint getvalue valuekey spo2set spo2 * if status is 'spo2status measurement_completed' ******************************************************************************************/ public void updatespo2 datapoint datapoint { int status = spo2status calculating; //"todo 5 1 " int spo2value = 0; //"todo 5 2 " trackerdatanotifier getinstance notifyspo2trackerobservers status, spo2value ; log d app_tag, datapoint tostring ; } in the heartratelistener java file, navigate to readvaluesfromdatapoint function, and read the heart rate data from datapoint get heart rate status using datapoint api key valuekey heartrateset heart_rate_status get heart rate value using datapoint api key valuekey heartrateset heart_rate get heart rate ibi value using datapoint api key valuekey heartrateset ibi_list get ibi quality using datapoint api key valuekey heartrateset ibi_status_list /******************************************************************************************* * [practice 6] read values from datapoint object * - get heart rate status * - get heart rate value * - get heart rate ibi value * - check retrieved heart rate’s ibi and ibi quality values ------------------------------------------------------------------------------------------- * - hint replace todo 6 with parts of code * 1 set hrdata status from 'datapoint' object using datapoint getvalue valuekey heartrateset heart_rate_status * 2 set hrdata hr from 'datapoint' object using datapoint getvalue valuekey heartrateset heart_rate * 3 set local variable 'list<integer> hribilist' using datapoint getvalue valuekey heartrateset ibi_list * 4 set local variable 'final list<integer> hribistatus' using datapoint getvalue valuekey heartrateset ibi_status_list * 5 set hrdata ibi with the last of 'hribilist' values * 6 set hrdata qibi with the last of 'hribistatus' values ******************************************************************************************/ public void readvaluesfromdatapoint datapoint datapoint { heartratedata hrdata = new heartratedata ; //"todo 6 1 " //"todo 6 2 " //"todo 6 3 " //"todo 6 4 " //"todo 6 5 " //"todo 6 6 " trackerdatanotifier getinstance notifyheartratetrackerobservers hrdata ; log d app_tag, datapoint tostring ; } run unit tests for your convenience, you can find an additional unit tests package this lets you verify your code changes even without using a physical watch see instructions below on how to run unit tests right click on com samsung health multisensortracking test and execute run 'tests in 'com samsung health multisensortracking'' command if you completed all the tasks correctly, you can see that all the unit tests passed successfully run the app after building the apk, you can run the application on a connected device to see blood oxygen level and heart rate values right after the app is started, it requests for user permission allow the app to receive data from the body sensors afterwards, it shows the application's main screen and automatically display the heart rate to get the blood oxygen level spo2 value, tap on the measure button to stop the measurement, tap on the stop button tap on the details label to see more heart rate data you're done! congratulations! you have successfully achieved the goal of this code lab now, you can create a health app that measures blood oxygen level and heart rate by yourself! if you're having trouble, you may download this file measuring blood oxygen level and heart rate complete code 158 8 kb to learn more about samsung health, visit developer samsung com/health
Learn Code Lab
codelabtransfer heart rate data from galaxy watch to a mobile device objective create a health app for galaxy watch, operating on wear os powered by samsung, to measure heart rate and inter-beat interval ibi , send data to a paired android phone, and create an android application for receiving data sent from a paired galaxy watch overview with this code lab, you can measure various health data using samsung health sensor sdk and send it to a paired android mobile device for further processing samsung health sensor sdk tracks various health data, but it cannot save or send collected results meanwhile, wearable data layer allows you to synchronize data from your galaxy watch to an android mobile device using a paired mobile device allows the data to be more organized by taking advantage of a bigger screen and better performance see samsung health sensor sdk descriptions for detailed information set up your environment you will need the following galaxy watch4 or newer android mobile device 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! heart rate data transfer sample code 213 7 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 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 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 the 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 to use the app, you need to enable developer mode in the 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 set up your android device click on the following links to setup your android device enable developer options run apps on a hardware device connect the galaxy watch with you samsung mobile phone start your project in android studio, click open to open an existing project locate the downloaded android project hrdatatransfer-code-lab from the directory and click ok you should see both devices and applications available in android studio as in the screenshots below initiate heart rate tracking noteyou may refer to this blog post for more detailed analysis of the heart rate tracking using samsung health sensor sdk first, you need to connect to the healthtrackingservice to do that create connectionlistener, create healthtrackingservice object by invoking healthtrackingservice connectionlistener, context invoke healthtrackingservice connectservice when connected to the health tracking service, check the tracking capability the available trackers may vary depending on samsung health sensor sdk, health platform versions or watch hardware version use the gettrackingcapability function of the healthtrackingservice object obtain heart rate tracker object using the function healthtrackingservice gethealthtracker healthtrackertype heart_rate_continuous define event listener healthtracker trackereventlistener, where the heart rate values will be collected start tracking the tracker starts collecting heart rate data when healthtracker seteventlistener updatelistener is invoked, using the event listener collect heart data from the watch the updatelistener collects datapoint instances from the watch, which contains a collection of valuekey objects those objects contain heart rate, ibi values, and ibi statuses there's always one value for heart rate while the number of ibi values vary from 0-4 both ibi value and ibi status lists have the same size go to wear > java > data > com samsung health hrdatatransfer > data under ibidataparsing kt, provide the implementation for the function below /******************************************************************************* * [practice 1] get list of valid inter-beat interval values from a datapoint * - return arraylist<int> of valid ibi values validibilist * - if no ibi value is valid, return an empty arraylist * * var ibivalues is a list representing ibivalues up to 4 * var ibistatuses is a list of their statuses has the same size as ibivalues ------------------------------------------------------------------------------- * - hints * use local function isibivalid status, value to check validity of ibi * ****************************************************************************/ fun getvalidibilist datapoint datapoint arraylist<int> { val ibivalues = datapoint getvalue valuekey heartrateset ibi_list val ibistatuses = datapoint getvalue valuekey heartrateset ibi_status_list val validibilist = arraylist<int> //todo 1 return validibilist } check data sending capabilities for the watch once the heart rate tracker can collect data, set up the wearable data layer so it can send data to a paired android mobile device wearable data layer api provides data synchronization between wear os and android devices noteto know more about wearable data layer api, go here to determine if a remote mobile device is available, the wearable data layer api uses concept of capabilities not to be confused with samsung health sensor sdk’s tracking capabilities, providing information about available tracker types using the wearable data layer's capabilityclient, you can get information about nodes remote devices being able to consume messages from the watch go to wear > java > com samsung health hrdatatransfer > data in capabilityrepositoryimpl kt, and fill in the function below the purpose of this part is to filter all capabilities represented by allcapabilities argument by capability argument and return the set of nodes set<node> having this capability later on, we need those nodes to send the message to them /************************************************************************************** * [practice 2] check capabilities for reachable remote nodes devices * - return a set of node objects out of all capabilities represented by 2nd function * argument, having the capability represented by 1st function argument * - return empty set if no node has the capability -------------------------------------------------------------------------------------- * - hints * you might want to use filtervalues function on the given allcapabilities map * ***********************************************************************************/ override suspend fun getnodesforcapability capability string, allcapabilities map<node, set<string>> set<node> { //todo 2 } encode message for the watch before sending the results of the heart rate and ibi to the paired mobile device, you need to encode the message into a string for sending data to the paired mobile device we are using wearable data layer api’s messageclient object and its function sendmessage string nodeid, string path, byte[] message go to wear > java > com samsung health hrdatatransfer > domain in sendmessageusecase kt, fill in the function below and use json format to encode the list of results arraylist<trackeddata> into a string /*********************************************************************** * [practice 3] - encode heart rate & inter-beat interval into string * - encode function argument trackeddata into json format * - return the encoded string ----------------------------------------------------------------------- * - hint * use json encodetostring function **********************************************************************/ fun encodemessage trackeddata arraylist<trackeddata> string { //todo 3 } notetrackeddata is an object, containing data received from heart rate tracker’s single datapoint object @serializable data class trackeddata var hr int, var ibi arraylist<int> = arraylist 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 or mobile device see the instruction below on how to run unit tests right click on com samsung health hrdatatransfer test , and execute run 'tests in 'com samsung health hrdatatransfer" command if you have completed all the tasks correctly, you will see all the unit tests pass successfully run the app after building the apks, you can run the applications on your watch to measure heart rate and ibi values, and on your mobile device to collect the data from your watch once the app starts, allow the app to receive data from the body sensors afterwards, it shows the application's main screen to get the heart rate and ibi values, tap the start button tap the send button to send the data to your mobile device notethe watch keeps last ~40 values of heart rate and ibi you’re done! congratulations! you have successfully achieved the goal of this code lab now, you can create a health app on a watch to measure heart rate and ibi, and develop a mobile app that receives that health data! if you face any trouble, you may download this file heart rate data transfer complete code 213 9 kb to learn more about samsung health, visit developer samsung com/health
Develop Health
blogthe global healthcare industry is undergoing a significant transformation. traditionally, healthcare systems have been fragmented, comprising various providers, insurers, and technologies that often lack seamless communication. this disconnection can result in inconsistent care, inefficiencies, and challenges in managing health effectively. while mobile apps and wearable devices are becoming more integrated into our daily lives, they primarily provide real-time data without offering a comprehensive understanding of overall health and wellness. digital health has the potential to bridge these gaps by fostering better personal health management through seamless communication and data sharing across devices, technologies, and providers. however, one of the key challenges in digital health adoption is integration. samsung has addressed this by developing one of the largest and most diverse digital health ecosystems, enabling different devices and partner solutions to work together within a unified platform. samsung health recognizes the crucial role connected devices can play in improving well-being. by delivering real-time data and insights, in a secured, hippa approved environment, these devices help individuals understand their health status, make informed lifestyle changes, and connect more efficiently with healthcare services. samsung’s ecosystem of devices and services provides a holistic approach to health and wellness, supporting individuals at every stage of life. this comprehensive wellness platform enables users to monitor their health data, gain valuable insights, and share information with healthcare providers for better decision-making. by fostering seamless healthcare experiences, we are shaping the future of digital health with smarter, more personalized solutions that enhance daily living and contribute to better health outcomes. at samsung, we believe in a healthier future—one where digital health plays a leading role in transforming care for individuals worldwide.
Learn Code Lab
codelabcreate a daily step counter on galaxy watch objective create a native app for galaxy watch, operating on wear os powered by samsung, using health platform to read your daily steps overview health platform provides a unified and straightforward way for accessing a wide range of health and wellness related data with health platform api, you may easily read and write data stored in health platform on android and wear os powered by samsung applications can have access to these secured data only with explicit user consent additionally, users may disable access to the data at any point in time see health platform descriptions for detailed information set up your environment you will need the following galaxy watch4 or newer android studio latest version recommended java se development kit jdk 11 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! health step count sample code 119 87 kb 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 debug over wi-fi turn off automatic wi-fi connect your galaxy watch to wi-fi go to settings > connection > wi-fi and make sure that wi-fi is enabled from the list of available wi-fi networks, choose and connect to the same one as your pc when successfully connected, tap a wi-fi network name, swipe down, and note the ip address you will need this to connect your watch over adb from your pc connect your galaxy watch to android studio in android studio, go to terminal and type adb connect <ip address as mentioned in previous step> when prompted, tap always allow from this computer to allow debugging 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 start your project after downloading the sample code containing the project files, in android studio click open to open existing project locate the downloaded android project stepcount from the directory and click ok check dependency and app manifest in the dependencies section of stepcount/app/build gradle file, see the appropriate dependency for health platform dependencies { implementation com google android libraries healthdata health-data-api 1 0 0-alpha01' // } notelibrary might update from time to time if necessary, choose the version suggested by android studio request for data permissions before accessing any data through health platform, the client app must obtain necessary permissions from the user in permissions java, create a permission instance to trigger relevant permission screen and obtain required consent from end user data type name intervaldatatypes steps read access accesstype read /******************************************************************************************* * [practice 1] build permission object grand permissions for read today's steps * - set interval data type of steps * - set read access type ------------------------------------------------------------------------------------------- * - hint uncomment lines below and fill todos with * 1 for interval data type intervaldatatypes steps * 2 for read access accesstype read ******************************************************************************************/ permission stepsreadpermission = permission builder // setdatatype "todo 1 1 " // setaccesstype "todo 1 2 " build ; make a query to aggregate today’s steps create read request with all necessary information to read data through health platform api the answer from the platform will be asynchronous with the result from which you can get all the data you are interested in follow the steps below to get today's steps count in stepsreader java, create a readaggregateddatarequest with cumulativeaggregationspec instance data type name intervaldatatypes steps /******************************************************************************************* * [practice 2] build read aggregated data request object for read today's steps * - set interval data type of steps ------------------------------------------------------------------------------------------- * - hint uncomment line below and fill todo 2 with * 1 for interval data type intervaldatatypes steps ******************************************************************************************/ readaggregateddatarequest readaggregateddatarequest = readaggregateddatarequest builder settimespec timespec builder setstartlocaldatetime localdatetime now with localtime midnight build // addcumulativeaggregationspec cumulativeaggregationspec builder "todo 2 1 " build build ; read cumulative steps count from cumulativedata set variable steps value to 0l it is the count of daily steps get aggregatedvalue object using cumulativedata api cumulativedataaggregateddata representing total of intervaldata over a period of time e g total steps in a day public aggregatedvalue gettotal check the result if it is not null, get aggregated value using aggregatedvalue api aggregatedvaluevalue fields aggregated over a period of time only numeric fields longfield, doublefield can be included in aggregation public long getlongvalue returns all longfields and their values that are already set add value to the daily steps result counter /******************************************************************************************* * [practice 3] read aggregated value from cumulative data and add them to the result * - get aggregatedvalue from cumulativedata object * - get steps count from aggregatedvalue object ------------------------------------------------------------------------------------------- * - hint uncomment lines below and replace todo 3 with parts of code * 1 get aggregatedvalue object 'obj' using cumulativedata gettotal * 2 get value using obj getlongvalue and add to the result ******************************************************************************************/ long steps = 0l; if result != null { list<cumulativedata> cumulativedatalist = result getcumulativedatalist ; if !cumulativedatalist isempty { for cumulativedata cumulativedata cumulativedatalist { //"todo 3 1 " //"todo 3 2 " } } } return steps; 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 instruction below on how to run unit tests right click on com samsung sdc21 stepcount test and execute run 'tests in 'com samsung sdc21 stepcount'' command if you completed all the tasks correctly, you will see all the unit tests passed successfully run the app after building the apk, you can run the application on a connected device to see real-life aggregated steps count measured by a smartwatch right after the app is started, it will request for the user permission allow the app to receive data of the activity afterwards, the application main screen will be shown it will automatically display today’s step count tap on refresh button to read current steps count from health platform you're done! congratulations! you have successfully achieved the goal of this code lab now, you can create a daily step counter app by yourself! if you're having trouble, you may download this file health step count complete code 119 79 kb learn more by going to health platform
Learn Code Lab
codelabmeasure 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
We use cookies to improve your experience on our website and to show you relevant advertising. Manage you settings for our cookies below.
These cookies are essential as they enable you to move around the website. This category cannot be disabled.
These cookies collect information about how you use our website. for example which pages you visit most often. All information these cookies collect is used to improve how the website works.
These cookies allow our website to remember choices you make (such as your user name, language or the region your are in) and tailor the website to provide enhanced features and content for you.
These cookies gather information about your browser habits. They remember that you've visited our website and share this information with other organizations such as advertisers.
You have successfully updated your cookie preferences.