Measure Electrodermal Activity on Galaxy Watch
measure electrodermal activity 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 electrodermal activity eda measurement results overview samsung health sensor sdk provides tools for accessing and tracking health information stored in the health data repository its tracking service delivers both raw and processed sensor data, including accelerometer readings and body composition metrics, collected by the samsung bioactive sensor electrocardiogram ecg , bioelectrical impedance analysis bia , photoplethysmogram ppg , heart rate, skin temperature, blood oxygen spo2 , and sweat loss data can be measured furthermore, the galaxy watch8 introduces electrodermal activity tracking electrodermal activity eda is a non-invasive physiological index that measures changes in skin conductance driven by sweat gland activity, reflecting the autonomic nervous system's response to both thermoregulation and psychological arousal see samsung health sensor sdk documentation for detailed information set up your environment you will need the following galaxy watch8 or newer android studio latest version recommended java se development kit jdk 17 or later android api level 36 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! electrodermal activity sample code 159 8 kb connect your galaxy watch with android studio watch the video below to connect to your galaxy watch for detailed instructions, visit this guide connect galaxy watch with android studio turn on developer mode for health platform watch the video below to enable developer mode for health platform on your galaxy watch for detailed instructions, visit this guide health platform’s developer mode start your project in android studio, click open to open existing project locate the downloaded android project edatracking from the directory and click select folder request for health permission the app utilizing samsung health sensor sdk requires the appropriate permissions and the user’s consent to access the vital signs information different permissions are required depending on the healthtrackertype you want to measure while this code lab focuses solely on healthtrackertype eda_continuous tracker type, the read_additional_health_data permission is also being used noteif the app’s target sdk version is android 15 api level 35 or lower, body_sensors permission is used go to app > manifests > androidmanifest xml and ensure the required permissions are added <uses-permission android name="android permission body_sensors" /> <uses-permission android name="com samsung android hardware sensormanager permission read_additional_health_data" /> next, the app needs to check if the user has already granted the permissions private fun ispermissiongranted = activitycompat checkselfpermission applicationcontext, permission!! == packagemanager permission_granted if no permission is granted, request the necessary permissions go to app > kotlin+java > com samsung health sensorsdksample edatracking > presentation > mainactivity kt and navigate to the preparepermission function complete the function to provide appropriate permissions based on the android version /**************************************************************************** * [practice 1] request health permissions * -------------------------------------------------------------------------- * * use the provided variable 'permission' * replace 'null' with proper value based on android version * if android sdk version is higher or equal android sdk 36 baklava use "com samsung android hardware sensormanager permission read_additional_health_data" permission * otherwise use "android permission body_sensors" ****************************************************************************/ fun preparepermission string? { val permission = if build version sdk_int >= build version_codes baklava { // todo replace 'null' with proper string value here null } else { // todo replace 'null' with proper string value here null } return permission } the returned permission is used in the requestpermissions function, which displays a pop-up asking for the user’s consent initialize eda tracker before starting the measurement, initialize the eda tracker by creating a healthtracker object navigate to app > kotlin+java > com samsung health sensorsdksample edatracking > tracking > edatrackingmanager kt and locate the obtainedatracker function using the provided healthtrackingservice object, create an instance of the healthtracker class with the eda_continuous type and assign it to the edatracker variable retrieve the healthtracker object using gethealthtracker use healthtrackertype eda_continuous as the parameter healthtrackerservice healthtrackerservice initiates a connection to samsung's health tracking service and provides an healthtracker instance to track a healthtrackertype healthtracker gethealthtracker healthtrackertype healthtrackertype provide a healthtracker instance for the given healthtrackertype /**************************************************************************** * [practice 2] setup eda tracker * -------------------------------------------------------------------------- * * use the provided variable 'edatracker' which is currently null * initialize eda tracker with proper sensor sdk functionality * call gethealthtracker function on 'healthtrackingservice' object * as an argument use healthtrackertype eda_continuous * assign the obtained tracker to 'edatracker' variable ****************************************************************************/ fun obtainedatracker healthtracker? { var edatracker healthtracker? = null // todo assign the tracker to the 'edatracker' variable here return edatracker } start and stop the tracker for the client app to begin retrieving data through the sdk, set a listener method on the healthtracker if successful, the event listener collects the sensor data until the measurement is stopped in the app noteonly one healthtracker trackereventlistener should be set per healthtrackertype healthtracker healthtracker enables an application to set an event listener and receive the galaxy watch's sensor data for a specific healthtrackertype void seteventlistener healthtracker trackereventlistener listener set an event listener for this healthtracker instance fun starttracking { edatracker = obtainedatracker if edatracker != null { edatracker!! seteventlistener trackerlistener _progressstate value = progressstate measuring true } else { scope launch { _messagestate emit messagestate trackernotinitialized } } } to stop the measurement, unset the trackereventlistener from the healthtracker object healthtracker healthtracker enables an application to set an event listener and receive the galaxy watch's sensor data for a specific healthtrackertype void unseteventlistener stop the registered event listener for this healthtracker instance fun stoptracking { if edatracker != null { edatracker!! unseteventlistener _progressstate value = progressstate measuring false } } obtain eda data the eda values are provided in the ondatareceived callback of trackereventlistener at a frequency of 1hz the platform's response is asynchronous and includes a data point object containing all the required information in the edatrackingmanager kt file, navigate to extractedavalues function to obtain eda data, read the skin conductance value and measurement status this can be extracted by specifying the appropriate keys in the getvalue function from the datapoint additionally, obtain the timestamp of the incoming data by calling the gettimestamp function from the datapoint retrieve the skin conductance value using the getvalue function with the key valuekey edaset skin_conductance retrieve the measurement status using the getvalue function with the key valuekey edaset status obtain the timestamp of the incoming data using the gettimestamp function datapoint datapoint is a map of valuekey and value with a timestamp long gettimestamp get a timestamp of the datapoint <t> t getvalue valuekey<t> type get a data value for the given key /**************************************************************************** * [practice 3] read values from datapoint object * - get skin conductance value * - get status value * - get timestamp * -------------------------------------------------------------------------- * * use the provided variable 'skinconductance' which is currently null * obtain skin conductance value using datapoint getvalue valuekey edaset skin_conductance * assign the obtained value into 'skinconductance' variable * * use the provided variable 'edastatus' which is currently null * obtain status using datapoint getvalue valuekey edaset status * assign the obtained value into 'edastatus' variable * * use the provided variable 'edatimestamp' which is currently null * obtain the 'timestamp' property from 'datapoint' object * assign the obtained value into 'edatimestamp' variable ****************************************************************************/ fun extractedavalues datapoint datapoint edavalue { var skinconductance float? = null var edastatus int? = null var edatimestamp long? = null // todo assign the skin_conductance value to the 'skinconductance' variable here // todo assign the status value to the 'edastatus' variable here // todo assign the timestamp property to the 'edatimestamp' variable here return edavalue skinconductance, edastatus fromint edastatus , edatimestamp } 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 the instructions below on how to run the unit tests right-click on com samsung health sensorsdksample edatracking test and select run ‘tests in ‘com samsung health sensorsdksample edatracking’’ 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 measure your electrodermal activity values once the application starts, grant the app permission to access your vital signs information tap the start button to begin the electrodermal activity measurement the app shows your skin conductance, measurement status, and the time of the recorded data tap the stop button to stop the measurement you're done! congratulations! you have successfully achieved the goal of this code lab now, you can create a health app that measures electrodermal activity eda on your own! if you are having trouble, you may download this file electrodermal activity complete code 159 3 kb to learn more about samsung health, visit developer samsung com/health