Filter
-
Content Type
-
Category
Mobile/Wearable
Visual Display
Digital Appliance
Platform
Recommendations
Filter
Develop Health
apioverviewpackageclasstreedeprecatedindex com samsung android sdk healthdata class healthdataresolver updaterequest builder java lang object com samsung android sdk healthdata healthdataresolver updaterequest builder enclosing interface healthdataresolver updaterequest public static class healthdataresolver updaterequest builder extends object this class is a builder to configure healthdataresolver updaterequest only inserted health data by your application can be updated the following example shows how to update calrories of existing health data public class healthdataresolverexample { private healthdataresolver updaterequest buildupdaterequest { healthdevice mydevice = new healthdevicemanager mstore getlocaldevice ; healthdata data = new healthdata ; data setsourcedevice mydevice getuuid ; data putfloat healthconstants nutrition calorie, 100 ; healthdataresolver filter filter = healthdataresolver filter eq healthconstants nutrition calorie, 10000 ; // build a request to update nutrition data which its calories is 10000 to 100 healthdataresolver updaterequest request = new healthdataresolver updaterequest builder setdatatype healthconstants nutrition health_data_type setfilter filter sethealthdata data build ; return request; } } since 1 0 0 constructor summary constructors constructor and description builder helps to construct a healthdataresolver updaterequest object method summary all methods instance methods concrete methods modifier and type method and description healthdataresolver updaterequest build builds a new healthdataresolver updaterequest object healthdataresolver updaterequest builder setdatatype string type sets a health data type to update healthdataresolver updaterequest builder setfilter healthdataresolver filter filter sets a filter for health data to update healthdataresolver updaterequest builder sethealthdata healthdata object sets a health data object to update healthdataresolver updaterequest builder setlocaltimerange string timeproperty, string offsetproperty, long begin, long end sets the local time range not to miss data from the query's result when there exist data with a different time_offset in the saved health data healthdataresolver updaterequest builder setsourcedevices list<string> uuidlist sets a uuid list of source devices for health data to be updated constructor detail builder public builder helps to construct a healthdataresolver updaterequest object since 1 0 0 method detail setdatatype public healthdataresolver updaterequest builder setdatatype string type sets a health data type to update it has to be specified before calling build parameters type - health_data_type of the data type returns the object that applies the health data type since 1 0 0 sethealthdata public healthdataresolver updaterequest builder sethealthdata healthdata object sets a health data object to update it has to be specified before calling build parameters object - the health data object to update the source device of object should be valid returns the object that applies health data to update since 1 0 0 setfilter public healthdataresolver updaterequest builder setfilter healthdataresolver filter filter sets a filter for health data to update parameters filter - the filter object to update returns the object that applies the filter since 1 0 0 setsourcedevices public healthdataresolver updaterequest builder setsourcedevices list<string> uuidlist sets a uuid list of source devices for health data to be updated parameters uuidlist - the uuid list for source devices returns the object that applies source devices since 1 0 0 setlocaltimerange public healthdataresolver updaterequest builder setlocaltimerange string timeproperty, string offsetproperty, long begin, long end sets the local time range not to miss data from the query's result when there exist data with a different time_offset in the saved health data the data that has a different time_offset with other data's time_offset can be saved when the daylight time is applied or the user moves to another region by like a travel building a complete query to aggregate all data including the different time_offset is not easy use this api to build an aggregate request as possible parameters timeproperty - the time property name that needs to add a filter offsetproperty - the time offset property begin - the beginning time of the local time range in milliseconds its minimum value is long min_value end - the end time of the local time range in milliseconds its maximum value is long max_value returns the object that applies the local time range since 1 5 0 build public healthdataresolver updaterequest build builds a new healthdataresolver updaterequest object check if following information is specified data type health data to update returns the healthdataresolver updaterequest object throws illegalstateexception - if data type, or health data object is not specified since 1 0 0 see also setdatatype string , sethealthdata healthdata
Develop Health
docapp creation process creating a wear os app is available with the samsung health sensor sdk a galaxy watch is also needed to develop and run the app find target device information more here sdk download download the samsung health sensor sdk and check the sdk content samsung health sensor sdk v1 3 0 2 47 mb enabling the developer mode you can check the sdk operation by turning on the health platform's developer mode notethe health platform's developer mode is intended solely for app development purposes it should not be used for your app users if you want to run your app without utilizing the developer mode, please submit the partner request developing your app create you app with importing the sdk library if you encounter any issue using the sdk, please submit your query on the developer support partner request to distribute your app please submit partner request before your app distribution your app's information including the app package name and signature sha-256 can be registered in the samsung health's system after an approval otherwise, the app using the samsung health sensor sdk works only with the developer mode turned on our partnership is an exclusive service for the samsung health sensor sdk that allows users to discover engaging health and fitness apps partnership request
Develop Health
apioverviewpackageclasstreedeprecatedindex com samsung android sdk healthdata class healthdataresolver readrequest builder java lang object com samsung android sdk healthdata healthdataresolver readrequest builder enclosing interface healthdataresolver readrequest public static class healthdataresolver readrequest builder extends object this class is a builder to configure healthdataresolver readrequest private healthdataresolver readrequest buildreadrequest long starttime, long endtime { healthdataresolver filter filter = healthdataresolver filter greaterthan healthconstants nutrition calorie, 200 ; healthdataresolver readrequest request = new healthdataresolver readrequest builder setdatatype healthconstants nutrition health_data_type setlocaltimerange healthconstants nutrition start_time, healthconstants nutrition time_offset, starttime, endtime setfilter filter build ; return request; } since 1 0 0 constructor summary constructors constructor and description builder helps to construct a healthdataresolver readrequest object method summary all methods instance methods concrete methods modifier and type method and description healthdataresolver readrequest build builds a new healthdataresolver readrequest object healthdataresolver readrequest builder setdatatype string type sets a health data type for the request to read healthdataresolver readrequest builder setfilter healthdataresolver filter filter sets a filter for the request to read healthdataresolver readrequest builder setlocaltimerange string timeproperty, string offsetproperty, long begin, long end sets the local time range not to miss data from the query's result when there exist data with a different time_offset in the saved health data healthdataresolver readrequest builder setpackagename string packagename sets the package name that provides health data to read healthdataresolver readrequest builder setproperties string[] properties sets a property array for the health data result to read healthdataresolver readrequest builder setpropertyalias string property, string alias sets an alias for the given property healthdataresolver readrequest builder setresultcount int offset, int count sets the count range of result data with a given offset and count healthdataresolver readrequest builder setsort string property, healthdataresolver sortorder sortorder sets the sort order for a given property or alias healthdataresolver readrequest builder setsourcedevices list<string> uuidlist sets a uuid list for source devices to read health data healthdataresolver readrequest builder settimeafter long time sets the time range to retrieve result data which is inserted or updated to the health data store after the given time constructor detail builder public builder helps to construct a healthdataresolver readrequest object since 1 0 0 method detail setdatatype public healthdataresolver readrequest builder setdatatype string type sets a health data type for the request to read it has to be specified before calling build parameters type - health_data_type of the data type returns the object that applies the health data type since 1 0 0 setfilter public healthdataresolver readrequest builder setfilter healthdataresolver filter filter sets a filter for the request to read parameters filter - the filter object returns the object that applies the filter since 1 0 0 setsourcedevices public healthdataresolver readrequest builder setsourcedevices list<string> uuidlist sets a uuid list for source devices to read health data parameters uuidlist - the uuid list for source devices returns the object that applies source devices since 1 0 0 setproperties public healthdataresolver readrequest builder setproperties string[] properties sets a property array for the health data result to read if it is not specified, the health data result shows all properties of the data type parameters properties - properties that want to gain in the result returns the object that applies properties since 1 0 0 setpropertyalias public healthdataresolver readrequest builder setpropertyalias string property, string alias sets an alias for the given property parameters property - the property to be shown with the alias alias - the alias for the property returns the object that applies the alias for the property since 1 0 0 setpackagename public healthdataresolver readrequest builder setpackagename string packagename sets the package name that provides health data to read accessory data's package name samsung health collects the linked accessory's data also like galaxy watch the accessory's data including galaxy watch is inserted to samsung health with the samsung health's package name, com sec android app shealth if you want to read only the specific accessory's data, make a division the device id parameters packagename - the package name that provides health data returns the object that applies the package name since 1 0 0 setsort public healthdataresolver readrequest builder setsort string property, healthdataresolver sortorder sortorder sets the sort order for a given property or alias parameters property - the property or alias to be shown with the sort order sortorder - the sort order returns the object that applies the sort order since 1 0 0 setresultcount public healthdataresolver readrequest builder setresultcount int offset, int count sets the count range of result data with a given offset and count if this method is not called, all result will be obtained from the result if you want to get only 10 data from the 3rd position in the result, set offset as 2 and count as 10 parameters offset - the start position in the whole result, which equals to or is greater than 0 count - the limited count of result, which is greater than 0 returns the object that applies the range of the result since 1 0 0 settimeafter public healthdataresolver readrequest builder settimeafter long time sets the time range to retrieve result data which is inserted or updated to the health data store after the given time it's different to set the time range based on the data's created or updated time to read data if then, use healthdataresolver filter greaterthan java lang string, t moreover it is useful to check the health data store's change after your app reads the health data store's data at the last time if the data's source device is same with the current device, time means the inserted time that data is created on the current device if the data's source device is different, time indicates the synchronized time that data on other devices is synchronized to samsung health of the current device parameters time - the time range to retrieve result data which is inserted or updated to the health data store after the specific time in milliseconds its value is started from january, 1, 1970 00 00 00 utc returns the object that applies the range of the result since 1 0 0 setlocaltimerange public healthdataresolver readrequest builder setlocaltimerange string timeproperty, string offsetproperty, long begin, long end sets the local time range not to miss data from the query's result when there exist data with a different time_offset in the saved health data the data that has a different time_offset with other data's time_offset can be saved when the daylight time is applied or the user moves to another region by like a travel building a complete query to read all data including the different time_offset is not easy use this api to build a read request as possible parameters timeproperty - the time property name that needs to add a filter offsetproperty - the time offset property begin - the beginning time of the local time range in milliseconds its minimum value is long min_value end - the end time of the local time range in milliseconds its maximum value is long max_value returns the object that applies the local time range since 1 3 0 build public healthdataresolver readrequest build builds a new healthdataresolver readrequest object check if following information is specified data type returns the healthdataresolver readrequest object throws illegalstateexception - if enough information is not specified since 1 0 0 see also setdatatype string
Develop Health
docfaq what are the benefits of the samsung health research stack? samsung health research stack provides end-to-end solutions for collecting and analyzing data from wearable devices in android and wear os environments and allows developers to design advanced health and wellness applications developers can also build research study portal which acts as a centralized hub for managing every facet of research studies, from enrollment to compliance how do i get access to the samsung health research stack? you can learn about accessing samsung health research stack here here what devices are compatible with samsung health research stack? the galaxy watch 5 and later has been tested for compatibility with this tech stack is it possible to contribute to samsung health research stack? yes, as an open-source project, samsung health research stack welcomes contributions from the developer community if you'd like to contribute, check out contributing to the open source project here how can i modify the ui on the starter-app? you can customize the ui by modifying the presentation package classes in starter mobile/wearable app specifically, you can edit the files in starter-mobile-app/src/main/kotlin/researchstack/presentation/ for theme or color changes, update the theme/appcolors kt file are the screens and flows for the mobile app available in android studio? yes, the screens and flows for the mobile app are available in android studio, and they are not configured in the container and backend how does data synchronization work in the app? the app uses android workmanager for periodic data sync once the user permits the use of their health data and finishes logging in, workmanager is initialized and periodically syncs health data from healthconnect to the backend, even when the app is not open what is the minimum interval for data sync, and can it be manually triggered? the least interval that can be set for data sync is 15 minutes workmanager cannot be manually triggered; it operates based on the configuration is it expected for data to only be pushed when the app is engaged? no, once workmanager is initialized, it syncs data periodically even when the app is not engaged various sequences of opening and closing the researchsample app and samsung health may trigger data transfer, but workmanager operates independently based on the configuration how do i modify the ui of the web portal? you might need to change ui materials before building the container please, contact our support to get a more precise answer how can i capture more types of health data from samsung health? there are two steps specify the app’s permissions for health connect in the health_permissions xml file, and add healthdatasyncspecs to mainactivity kt the healthconnectadapter currently supports 11 types of health data alternatively, you could utilize samsung health sdks what should i do if the account verification email is not sent when creating a web portal account? ensure that smtp access is activated on the account and that outbound calls on the corresponding smtp port are allowed from your server if using 2-factor authentication 2fa , try signing in with an app password if not, you might need to allow less secure apps to access your account what could cause authentication issues when sending emails from the account service? if you are using 2-factor authentication 2fa , try signing in with an app password if it does not work, you might need to allow less secure apps to access your account where can i find logs or monitor the workmanager for debugging? you can briefly monitor the workmanager in the "app inspection" tab in android studio how can i monitor and troubleshoot workmanager for data synchronization? you can monitor workmanager in the "app inspection" tab in android studio this can help you check if data sync is happening as expected and identify any issues how can i change the configuration for data synchronization? the data synchronization process is handled by workmanager, and the interval for data sync is set in the configuration you can modify this configuration according to your needs, but the minimum interval that can be set is 15 minutes missing google-services json file in the source code if you want to use firebase to provide a 3rd party login to users the google-services json file must be included in the source code a reference to integrate it can be found here need guidance on backend installation for the app the app fetches project information such as surveys and activity tasks from the backend for testing, it's recommended to follow the backend installation guide instead of integrating your own backend system detailed instructions can be found here how to capture and export accelerometry continuously, not just during the activity task? the app regularly sends health data logged by health connect at intervals that can be set by the user for sensor data related to each activity task, it's collected & synced when the activity is conducted specific activity tasks and their associated sensor types are provided what data types from health connect can be utilized? the app can utilize all data types supported by health connect by modifying the list of healthdatarequired, you can adjust the app to collect additional data types recorded by health connect however, to have data input, that data needs to exist in health connect resolution to /gradlew clean failing for app-sdk? this appears to be an issue with the system failing to communicate with the gradle plugin repository ensure that your system is online, and if you're using a proxy environment, check proxy settings if a proxy is in use, the issue might be an ssl handshake failure check ssl settings and proxy configurations
Develop Health
apioverviewpackageclasstreedeprecatedindex com samsung android sdk healthdata class healthpermissionmanager java lang object com samsung android sdk healthdata healthpermissionmanager public class healthpermissionmanager extends object this class requests permission to read or write health data for the specific health data type note, healthconstants healthdocument can be accessed with the instant permission see acquring instant data permission requesting permission an application can access health data only if the user consents permission for data access can be requested by each data type and the permission type read or write public class mainactivity extends activity { // the state of connection private healthdatastore mstore; set<permissionkey> mkeys = new hashset<permissionkey> ; private static final string app_tag = "myapp"; public void requestpermission { // acquire permission healthpermissionmanager pmsmanager = new healthpermissionmanager mstore ; mkeys add new permissionkey exercise health_data_type, permissiontype read ; mkeys add new permissionkey exercise health_data_type, permissiontype write ; mkeys add new permissionkey stepdailytrend health_data_type, permissiontype read ; try { pmsmanager requestpermissions mkeys, mainactivity this setresultlistener mpermissionlistener ; } catch exception e { log d app_tag, "requestpermissions fails" ; } } if requestpermissions succeeds, the permission ui is popped up on the device the user can check and allow each data type's permission with scrolling down if the user allows permission items on the permission ui and select "done", its result is sent to permissionresult and you can check whether the user allows the data access or not private final healthresultholder resultlistener<permissionresult> mpermissionlistener = new healthresultholder resultlistener<permissionresult> { @override public void onresult permissionresult result { map<permissionkey, boolean> resultmap = result getresultmap ; if resultmap values contains boolean false { log d app_tag, "all required permissions are not granted " ; } else { log d app_tag, "all required permissions are granted " ; //access health data } } }; } specifying permission in manifest not only calling permission related apis, but specifying permission in the manifest file is required the declared permission items in the application's manifest are shown on "samsung health > settings > data permissions > [yourapp]" manifest below contains two data permissions to read and one data permission to write health data use the semicolon ; to declare multiple data types <manifest > <application > <meta-data android name="com samsung android health permission read" android value="com samsung health exercise;com samsung shealth step_daily_trend"/> <meta-data android name="com samsung android health permission write" android value="com samsung health exercise"/> </application> </manifest> the constant value of the required data type can be checked as shown below find its health_data_type in api reference e g if the data type is healthconstants exercise, you'll meet the following description use the constant value, "com samsung health exercise", for a permission declaration in your app's manifest file guidelines for permission request acquiring permission from the user is essential to access health data but too frequent requests of permission can annoy the user here are guidelines that help you to find a solution for the permission request permission needs to be requested in the following cases when your application connects to samsung health at the first time if there is a menu that connects to samsung health in your application and the user selects it and avoid requesting permission in the following cases when your application goes on the background frequent requests of permission until the user grants an occasional nudge is fine see the privacy section of programming guide for more information since 1 0 0 nested class summary nested classes modifier and type class and description static class healthpermissionmanager permissionkey this class represents the permission key which consists of a health data type and a permission type static class healthpermissionmanager permissionresult this class represents the result of requestpermissions set, activity static class healthpermissionmanager permissiontype this enum defines the permission type to read or write health data constructor summary constructors constructor and description healthpermissionmanager healthdatastore store constructs and initializes an instance of healthpermissionmanager method summary all methods instance methods concrete methods deprecated methods modifier and type method and description map<healthpermissionmanager permissionkey,boolean> ispermissionacquired set<healthpermissionmanager permissionkey> permissionkeys checks whether the specified permissions are acquired healthresultholder<healthpermissionmanager permissionresult> requestpermissions set<healthpermissionmanager permissionkey> permissionkeys deprecated use requestpermissions set, activity instead of it healthresultholder<healthpermissionmanager permissionresult> requestpermissions set<healthpermissionmanager permissionkey> permissionkeys, activity activity requests permissions through the permission ui on the given activity constructor detail healthpermissionmanager public healthpermissionmanager healthdatastore store constructs and initializes an instance of healthpermissionmanager parameters store - the successful connection to the health data store since 1 0 0 method detail requestpermissions public healthresultholder<healthpermissionmanager permissionresult> requestpermissions set<healthpermissionmanager permissionkey> permissionkeys deprecated use requestpermissions set, activity instead of it requests permissions through the permission ui if it is called, the permission ui is shown to the user avoid calling this method frequently refer to its guidelines parameters permissionkeys - the set of required permission keys returns the permission result that resolves to the requested permission keys throws illegalargumentexception - if the permissionkeys is invalid illegalstateexception - if the connection to the health data store is invalid or a remote-invocation error occurs on the connection since 1 0 0 requestpermissions public healthresultholder<healthpermissionmanager permissionresult> requestpermissions set<healthpermissionmanager permissionkey> permissionkeys, activity activity requests permissions through the permission ui on the given activity if it is called, the permission ui is shown to the user avoid calling this method frequently refer to its guidelines parameters permissionkeys - the set of required permission keys activity - the activity that pop up the permission ui returns the permission result that resolves to the requested permission keys throws illegalargumentexception - if the permissionkeys is invalid illegalstateexception - if the connection to the health data store is invalid or a remote-invocation error occurs on the connection since 1 2 0 ispermissionacquired public map<healthpermissionmanager permissionkey,boolean> ispermissionacquired set<healthpermissionmanager permissionkey> permissionkeys checks whether the specified permissions are acquired parameters permissionkeys - the set of permission keys to check acquisition returns the result map representing whether the specified permissions are acquired the permission state for the specific permission key can be retrieved by map get object as the following example public class healthpermissionmanagerexample { // the state of connection private healthdatastore mstore; private static final string app_tag = "myapp"; private void checkpermissions { healthpermissionmanager pmsmanager = new healthpermissionmanager mstore ; set<healthpermissionmanager permissionkey> keys = new hashset<healthpermissionmanager permissionkey> ; healthpermissionmanager permissionkey key1 = new healthpermissionmanager permissionkey healthconstants bloodglucose health_data_type, healthpermissionmanager permissiontype read ; keys add key1 ; healthpermissionmanager permissionkey key2 = new healthpermissionmanager permissionkey healthconstants bloodpressure health_data_type, healthpermissionmanager permissiontype read ; keys add key2 ; try { map resultmap = pmsmanager ispermissionacquired keys ; if resultmap get key1 == boolean true { log d app_tag, "you can read the blood glucose data type " ; } else { log d app_tag, "there is no permission to read the blood glucose data type " ; } if resultmap get key2 == boolean true { log d app_tag, "you can read the blood pressure data type " ; } else { log d app_tag, "there is no permission to read the blood pressure data type " ; } } catch exception e { log d app_tag, "check the connection " ; } } } throws illegalargumentexception - if the permissionkeys is invalid illegalstateexception - if the connection to the health data store is invalid or a remote-invocation error occurs on the connection since 1 0 0
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
docdata viewer dataviewer is a very useful tool to check saved data in samsung health you can find it in the downloaded sdk's /data/tools folder prerequisites install dataviewer and open it activating the developer mode is not required from samsung health 6 11 dataviewer provides the sdk's supported data type list and some useful menus the following figure shows its main screen and corresponding menus checking saved data you can check the saved data in samsung health by selecting one of the data types in the figure below each data type can be accessed after the data permission agreement whenever you select a data type on the mains screen’s data list, the permission ui displays then saved data in samsung health are listed up with its respective timestamp by selecting each data type, you can see detailed data info including its measured time or a source app package name checking the saved data with dataviewer is the exact way to test your app when it writes measured data to samsung health the inserted data cannot be shown on samsung health caused by its ui policy or wrong setting of "start_time" and "time_offset" make sure to set the following information well especially measured data value and its unit "start_time" that indicates the measurement time and "time_offset"
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
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
docmissing google-services json file in the source code for firebase integration the app uses firebase to provide a 3rd party login to users the google-services json file must be included in the source code a reference to integrate it can be found here need guidance on backend installation for the app the app fetches project information such as surveys and activity tasks from the backend for testing, it's recommended to follow the backend installation guide instead of integrating your own backend system detailed instructions can be found here error encountered while trying to build the modules related to healthstack sample the error seems to arise from a missing client for the package name 'healthstack sample' ensure that the correct configurations are available and that the associated files for this client are not missing possibility of using the graphics and ui from the samsung health app in the new build no specific answer provided in the email chain, would need further follow-up how to capture and export accelerometry continuously, not just during the activity task? the app regularly sends over health data logged by health connect at intervals that can be set by the user for sensor data related to each activity task, it's collected & synced when the activity is conducted specific activity tasks and their associated sensor types were provided which data types from health connect can be utilized? the app can utilize all data types supported by health connect by modifying the list of healthdatarequired, you can adjust the app to collect additional data types recorded by health connect however, to have data input, that data needs to exist in health connect resolution to /gradlew clean failing for app-sdk? this appears to be an issue with the system failing to communicate with the gradle plugin repository ensure that your system is online, and if you're using a proxy environment, check proxy settings if a proxy is in use, the issue might be an ssl handshake failure check ssl settings and proxy configurations
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.