• Learn
    • Code Lab
    • Foldables and Large Screens
    • One UI Beta
    • Samsung Developers Podcasts
  • Develop
    • Mobile/Wearable
    • Galaxy GameDev
    • Galaxy Themes
    • Galaxy Watch
    • Health
    • Samsung Blockchain
    • Samsung DeX
    • Samsung IAP
    • Samsung Internet
    • Samsung Pay
    • Samsung Wallet
    • View All
      • Galaxy AR Emoji
      • Galaxy Accessory
      • Galaxy Edge
      • Galaxy Z
      • Galaxy Performance
      • Galaxy FM Radio
      • Galaxy S Pen Remote
      • Galaxy Sensor Extension
      • PENUP
      • Samsung Automation
      • Samsung Neural
      • Samsung TEEGRIS
      • Samsung eSE SDK
      • Galaxy Watch for Tizen
      • Watch Face Studio
      • One UI Watch for Tizen
      • Galaxy Watch Studio Converter
      • Samsung IAP for Galaxy Watch (Tizen)
    • Visual Display
    • Smart TV
    • Smart Hospitality Display
    • Smart Signage
    • Digital Appliance
    • Family Hub
    • Platform
    • Bixby
    • Knox
    • SmartThings
    • Tizen.NET
  • Design
    • Design System
    • One UI
    • One UI Watch
    • Smart TV
  • Distribute
    • Galaxy Store
    • TV Seller Office
    • Galaxy Store Games
    • Samsung Podcasts
  • Support
    • Developer Support
    • Remote Test Lab
    • Issues and Bugs Channel
    • Samsung Android USB Driver
    • Galaxy Emulator Skin
  • Connect
    • Blog
    • News
    • Forums
    • Events
    • Samsung Developer Conference
    • SDC23
    • SDC22
    • SDC21
    • SDC19 and Previous Events
  • Sign In
Top Global Search Form
Recommendation
  • Blog
  • Code Lab
  • Foldable and Large Screen Optimization
  • Forums
  • Galaxy Emulator Skin
  • Galaxy GameDev
  • Health
  • Remote Test Lab
  • Samsung Developer Conference
  • SDC22
  • Watch Face Studio
All Search Form
Recommendation
    Suggestion
      All Search Form
      Filter
      Filter
      Filter
      • ALL
      • DOCS (100)
      • SDK
      • API REFERENCE
      • CODE LAB
      • BLOG
      • NEWS/EVENTS
      • OTHERS
        api reference code lab blog news/events
      1. Develop
      2. Health

      api

      HealthPermissionManager

      overview package class tree deprecated index 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

      https://developer.samsung.com/health/android/data/api-reference/com/samsung/android/sdk/healthdata/HealthPermissionManager.html
      1. Develop
      2. Health

      api

      HealthUserProfile

      overview package class tree deprecated index com.samsung.android.sdk.healthdata class healthuserprofile java.lang.object com.samsung.android.sdk.healthdata.healthuserprofile public class healthuserprofile extends object this class provides a user profile. it handles the user's following information: date of birth gender height weight nickname getting user profile samsung health's user profile is read-only and you can get it after acquiring the user's permission. set the user profile data type's permission info in the manifest. <manifest . . . > <application . . . > <meta-data android:name="com.samsung.android.health.permission.read" android:value="com.samsung.health.user_profile"/> </application . . . > </manifest . . . > getting the user profile is same with other data type access. returning an empty string, 0.0, or unknown value can be retrieved for each property means that the user doesn't fill out samsung health's profile. public class mainactivity extends activity { // the state of connection private healthdatastore mstore; // permission key set set<healthpermissionmanager.permissionkey> mkeyset = new hashset<healthpermissionmanager.permissionkey>(); public static final string app_tag = "myapp"; private void getuserprofile() { // adds a permission to read a user profile to the permission key set mkeyset.add(new healthpermissionmanager.permissionkey(healthconstants.user_profile_data_type, healthpermissionmanager.permissiontype.read)); healthpermissionmanager pmsmanager = new healthpermissionmanager(mstore); try { // checks if a user profile permission is acquired map<healthpermissionmanager.permissionkey, boolean> keymap = pmsmanager.ispermissionacquired(mkeyset); // request permission if the user profile permission is not acquired if(keymap.containsvalue(boolean.false)) { pmsmanager.requestpermissions(mkeyset, mainactivity.this).setresultlistener(mpermissionlistener); } } catch(exception e) { log.d(app_tag, "requestpermissions() fails."); } } private final healthresultholder.resultlistener<healthpermissionmanager.permissionresult> mpermissionlistener = new healthresultholder.resultlistener<healthpermissionmanager.permissionresult>() { @override public void onresult(healthpermissionmanager.permissionresult permissionresult) { map<healthpermissionmanager.permissionkey, boolean> resultmap = permissionresult.getresultmap(); if (resultmap.containsvalue(boolean.true)) { // gets the user profile if permission is acquired try { healthuserprofile usrprofile = healthuserprofile.getprofile(mstore); // date of birth - yyyymmdd string birthdate = usrprofile.getbirthdate(); if (birthdate.isempty()) { log.d(app_tag, "date of birth is not set by the user yet."); } // gender int gender = usrprofile.getgender(); if (gender == healthuserprofile.gender_unknown) { log.d(app_tag, "gender is not set by the user yet."); } // height float height = usrprofile.getheight(); if (height == 0.0f) { log.d(app_tag, "height is not set by the user yet."); } // weight float weight = usrprofile.getweight(); if (weight == 0.0f) { log.d(app_tag, "weight is not set by the user yet."); } } else { log.d(tag, "fail to get permission."); } } }; } since: 1.0.0 field summary fields modifier and type field and description static int gender_female female as the value of gender. static int gender_male male as the value of gender. static int gender_unknown unknown as the value of gender. method summary all methods static methods instance methods concrete methods deprecated methods modifier and type method and description string getbirthdate() gets the user's date of birth. int getgender() gets the gender of the user. float getheight() gets the latest height of the user. bitmap getimage() deprecated. it will removed. do not use any more. static healthuserprofile getprofile(healthdatastore store) gets a healthuserprofile instance. string getuserid() deprecated. it will removed. do not use any more. string getusername() gets the nickname that the user entered in samsung health. float getweight() gets the latest weight of the the user. field detail gender_unknown public static final int gender_unknown unknown as the value of gender. its constant value is 0. see also: constant field values gender_male public static final int gender_male male as the value of gender. its constant value is 1. see also: constant field values gender_female public static final int gender_female female as the value of gender. its constant value is 2. see also: constant field values method detail getprofile public static healthuserprofile getprofile(healthdatastore store) gets a healthuserprofile instance. it works after acquiring permission for healthconstants.user_profile_data_type. parameters: store - the connection to the health data store returns: the healthuserprofile instance throws: illegalargumentexception - if the specified input is invalid illegalstateexception - if the connection to the health data store is invalid or a remote-invocation error occurs on the connection securityexception - if permission for healthconstants.user_profile_data_type is not acquired since: 1.0.0 getbirthdate public string getbirthdate() gets the user's date of birth. returns: the user's date of birth with the yyyymmdd format. if it returns the empty string, it means the user doesn't set the birth date on the profile page of samsung health. since: 1.0.0 getheight public float getheight() gets the latest height of the user. the unit is centimeter. returns: the height of the user. if it returns 0.0, it means the user doesn't set the height on the profile page of samsung health. since: 1.0.0 getweight public float getweight() gets the latest weight of the the user. the unit is kilogram. returns: the weight of the user. if it returns 0.0, it means the user doesn't set the weight on the profile page of samsung health. since: 1.0.0 getuserid @deprecated public string getuserid() deprecated. it will removed. do not use any more. gets an empty string. returns: empty string since: 1.0.0 getgender public int getgender() gets the gender of the user. returns: the gender of the user. one of the following values is returned. gender_unknown, if the user doesn't set the gender info on the profile page of samsung health gender_male gender_female since: 1.0.0 getusername public string getusername() gets the nickname that the user entered in samsung health. returns: the user's nickname. it returns the empty string. since: 1.2.0 getimage @deprecated public bitmap getimage() deprecated. it will removed. do not use any more. gets null. returns: null. since: 1.2.0

      https://developer.samsung.com/health/android/data/api-reference/com/samsung/android/sdk/healthdata/HealthUserProfile.html
      1. Develop
      2. Health

      api

      HealthDataResolver.ReadRequest

      overview package class tree deprecated index com.samsung.android.sdk.healthdata interface healthdataresolver.readrequest enclosing class: healthdataresolver public static interface healthdataresolver.readrequest this interface is able to make a request to read health data for the specific health data type. request for reading data healthdataresolver.read() helps that your application reads samsung health's data. the following information is mandatory to build a readrequest instance. mandatory information description data type set the data type with: readrequest.builder.setdatatype() you can make a request instance with readrequest.builder.build(). reading data example you can read samsung health's health data with healthdataresolver.read(). the filter below is created to read today's step count. the time range is set from the starttime to endtime. // the state of connection private final healthdatastore mstore; public static final string app_tag = "myapp"; private static final long one_day_in_millis = 24 * 60 * 60 * 1000l; private long getstarttimeoftoday() { calendar today = calendar.getinstance(timezone.gettimezone("utc")); today.set(calendar.hour_of_day, 0); today.set(calendar.minute, 0); today.set(calendar.second, 0); today.set(calendar.millisecond, 0); return today.gettimeinmillis(); } an readrequest instance is created by readrequest.builder.build() with setting the data type and the range for reading data. private void readtodaystepcount() { // set time range from start time of today to the current time long starttime = getstarttimeoftoday(); long endtime = starttime + one_day_in_millis; healthdataresolver.readrequest request = new readrequest.builder() .setdatatype(healthconstants.stepcount.health_data_type) .setproperties(new string[] {healthconstants.stepcount.count}) .setlocaltimerange(healthconstants.stepcount.start_time, healthconstants.stepcount.time_offset, starttime, endtime) .build(); readrequest.read() sends a reading request to samsung health. the asynchronous request is used generally by setting a listener. healthdataresolver resolver = new healthdataresolver(mstore, null); try { resolver.read(request).setresultlistener(mlistener); } catch (exception e) { log.d(myapp, "getting step count fails."); } } the result is sent to the implemented listener. the today's total count is returned by adding all count values of the result. private final healthresultholder.resultlistener<readresult> mlistener = new healthresultholder.resultlistener<readresult>() { @override public void onresult(readresult result) { int count = 0; try { iterator<healthdata> iterator = result.iterator(); if (iterator.hasnext()) { healthdata data = iterator.next(); count += data.getint(healthconstants.stepcount.count); } } finally { result.close(); } } }; since: 1.0.0 nested class summary nested classes modifier and type interface and description static class healthdataresolver.readrequest.builder this class is a builder to configure healthdataresolver.readrequest.

      https://developer.samsung.com/health/android/data/api-reference/com/samsung/android/sdk/healthdata/HealthDataResolver.ReadRequest.html
      1. Develop
      2. Health

      api

      HealthPermissionManager.PermissionKey

      overview package class tree deprecated index com.samsung.android.sdk.healthdata class healthpermissionmanager.permissionkey java.lang.object com.samsung.android.sdk.healthdata.healthpermissionmanager.permissionkey enclosing class: healthpermissionmanager public static class healthpermissionmanager.permissionkey extends object this class represents the permission key which consists of a health data type and a permission type. it is used as a key to request permission and checks the permission state. since: 1.0.0 constructor summary constructors constructor and description permissionkey(string datatype, healthpermissionmanager.permissiontype permissiontype) creates a permissionkey instance. method summary all methods instance methods concrete methods modifier and type method and description boolean equals(object obj) checks if this instance is equal with the given object. string getdatatype() gets the health data type of the permission key. healthpermissionmanager.permissiontype getpermissiontype() gets the permission type of the permission key. int hashcode() returns a hash code value for this instance. constructor detail permissionkey public permissionkey(string datatype, healthpermissionmanager.permissiontype permissiontype) creates a permissionkey instance. parameters: datatype - the health data type permissiontype - the permission type since: 1.0.0 method detail getdatatype public string getdatatype() gets the health data type of the permission key. returns: the health data type since: 1.0.0 getpermissiontype public healthpermissionmanager.permissiontype getpermissiontype() gets the permission type of the permission key. returns: the permission type since: 1.0.0 equals public boolean equals(object obj) checks if this instance is equal with the given object. in other to be equal, obj must an instance of permissionkey. overrides: equals in class object parameters: obj - the permissionkey object to compare this instance with returns: true if the given object is equal to this instance, or false see also: hashcode() hashcode public int hashcode() returns a hash code value for this instance. if equals(object) returns true for two objects, their hash code values are same. overrides: hashcode in class object returns: the hash code value for this instance see also: equals(object)

      https://developer.samsung.com/health/android/data/api-reference/com/samsung/android/sdk/healthdata/HealthPermissionManager.PermissionKey.html
      1. Develop
      2. Health

      api

      HealthPermissionManager.PermissionType

      overview package class tree deprecated index com.samsung.android.sdk.healthdata enum healthpermissionmanager.permissiontype java.lang.object java.lang.enum<healthpermissionmanager.permissiontype> com.samsung.android.sdk.healthdata.healthpermissionmanager.permissiontype all implemented interfaces: serializable, comparable<healthpermissionmanager.permissiontype> enclosing class: healthpermissionmanager public static enum healthpermissionmanager.permissiontype extends enum<healthpermissionmanager.permissiontype> this enum defines the permission type to read or write health data. since: 1.0.0 enum constant summary enum constants enum constant and description read permission to read health data. write permission to write health data. method summary all methods static methods instance methods concrete methods modifier and type method and description int getvalue() gets value of the permission type. static healthpermissionmanager.permissiontype valueof(string name) returns the enum constant of this type with the specified name. static healthpermissionmanager.permissiontype[] values() returns an array containing the constants of this enum type, in the order they are declared. enum constant detail read public static final healthpermissionmanager.permissiontype read permission to read health data. since: 1.0.0 write public static final healthpermissionmanager.permissiontype write permission to write health data. since: 1.0.0 method detail values public static healthpermissionmanager.permissiontype[] values() returns an array containing the constants of this enum type, in the order they are declared. this method may be used to iterate over the constants as follows: for (healthpermissionmanager.permissiontype c : healthpermissionmanager.permissiontype.values()) system.out.println(c); returns: an array containing the constants of this enum type, in the order they are declared valueof public static healthpermissionmanager.permissiontype valueof(string name) returns the enum constant of this type with the specified name. the string must match exactly an identifier used to declare an enum constant in this type. (extraneous whitespace characters are not permitted.) parameters: name - the name of the enum constant to be returned. returns: the enum constant with the specified name throws: illegalargumentexception - if this enum type has no constant with the specified name nullpointerexception - if the argument is null getvalue public int getvalue() gets value of the permission type. returns: the value of the permission type, read or write since: 1.0.0

      https://developer.samsung.com/health/android/data/api-reference/com/samsung/android/sdk/healthdata/HealthPermissionManager.PermissionType.html
      1. Develop
      2. Health

      doc

      FoodNote

      data | foodnote foodnote sample download | apr 11, 2019 (nov 3, 2020) the sdk's health data provides a foodnote sample application to show how to manage nutrition data with samsung health after the permission request. prerequisites prerequisites to run foodnote are: prepare an android device that supports android 6.0 marshmallow (api level 23) or above. (samsung and non-samsung devices are available both.) add the foodnote app's dev access code developer mode. client id: com.samsung.android.app.foodnote access code: qeca0zbm import foodnote with android studio (or eclipse). run foodnote on the device. overview foodnote demonstrates how to use health data's apis for checking the selected day's food intake with healthconstants.nutrition including permission request. especially, the health data store connection and exception handling would be helpful to your application to prepare unexpected error. foodnote's sources and resources are: source / resource description androidmanifest.xml declaring required permissions with the <meta-data> element. java/com/samsung/android/app/foodnote appconstants.java getting the meal type name. choosefoodactivity.java loading the food list of the foodinfotable class and showing them that the user can choose. fooddatahelper.java inserting nutrition data. deleting nutrition data. reading nutrition data of the selected day and the meal type. foodinfotable.java defining sample food information. mainactivity.java foodnote's main activity. connecting to the health data store and handling exceptions through connectionlistener. checking permission for healthconstants.nutrition and requesting permission if required. creating an option menu for setting permission. showing the selected day's calorie intake. adding an observer to get notification for the calorie change. mealstoreactivity.java showing a list of food intake items for the selected meal that is chosen on mainactivity. deleting a food intake item in the list.

      https://developer.samsung.com/health/android/sample/food-note.html
      1. Develop
      2. Health

      doc

      SimpleHealth

      data | simpleheath simplehealth sample download (nov 3, 2020) the sdk's health data provides a simplehealth sample application to read the today's step count. prerequisites prerequisites to run simplehealth are: prepare an android device that supports android 6.0 marshmallow (api level 23) or above. (samsung and non-samsung devices are available both.) add the simplehealth app's dev access code developer mode. client id: com.samsung.android.simplehealth access code: zc1modem import simplehealth with android studio (or eclipse). run simplehealth on the device. overview simplehealth demonstrates how to use health data's apis for retrieving the today's step count with healthconstants. stepcount data type and healthdataobserver. especially, the health data store connection and exception handling would be helpful to your application to prepare unexpected error. simplehealth's sources and resources are: source / resource description androidmanifest.xml declaring required permissions with the <meta-data> element. java/com/samsung/android/simplehealth mainactivity.java simplehealth's main activity. connecting to the health data store and handling exceptions through connectionlistener. checking permission to read healthconstants.stepcount and requesting permission if required. creating an option menu for setting permission. showing today's step count. stepcountreporter.java reading today's total steps asynchronously. adding an observer to get notification for the step count's change.

      https://developer.samsung.com/health/android/sample/simple-health.html
      1. Learn
      2. Code Lab

      codelab

      Create a Daily Step Counter on Galaxy Watch

      create 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.

      https://developer.samsung.com/codelab/health/daily-step-counter.html
      1. Develop
      2. Health

      api

      HealthConstants.HealthDocument

      overview package class tree deprecated index com.samsung.android.sdk.healthdata interface healthconstants.healthdocument all superinterfaces: healthconstants.common, healthconstants.discretemeasurement enclosing class: healthconstants public static interface healthconstants.healthdocument extends healthconstants.discretemeasurement this interface defines health docuemnt data of the user. this data type helps to handle the cda and pdf health document. properties properties of the following extending interfaces are available for this data type. healthconstants.common healthconstants.discretemeasurement health document data has the following properties. see more common properties by spreading this section out. property name description healthconstants.healthdocument.uuid [mandatory] data's unique id, assigned by the system when a new data is inserted healthconstants.healthdocument.create_time [mandatory] utc milliseconds when a data is created in the health data store, assigned by the system when a new data is inserted healthconstants.healthdocument.update_time [mandatory] utc milliseconds when a data is updated in the health data store, assigned by the system when a new data is inserted or the existing data is updated healthconstants.healthdocument.package_name [mandatory] package name which provides data, assigned by the system when a new data is inserted healthconstants.healthdocument.device_uuid [mandatory] device identifier which provides the health data healthconstants.healthdocument.start_time [mandatory] utc milliseconds when the measurement is started healthconstants.healthdocument.time_offset [mandatory] time offset in milliseconds which considers the time zone and daylight saving time healthconstants.healthdocument.type [mandatory] document type healthconstants.healthdocument.document [mandatory] document file healthconstants.healthdocument.id [mandatory] document id healthconstants.healthdocument.title [mandatory] document title healthconstants.healthdocument.patient [mandatory] patient name healthconstants.healthdocument.custodian [mandatory] custodian or hospital name that manages this document healthconstants.healthdocument.patient_gender gender code of patient healthconstants.healthdocument.patient_birthdate patient birth date with the yyyymmdd format healthconstants.healthdocument.author author or doctor name who write this document healthconstants.healthdocument.custom custom info which is formatted with json and compressed data data permission the health document access is allowed with the instant permission. the instant permission can be gained with the following apis. healthdataresolver.insertwithpermission() healthdataresolver.readwithpermission() healthdataresolver.deletewithpermission() see acquring instant data permission. since: 1.3.0 field summary fields modifier and type field and description static string author author or doctor name who write this document. static string custodian custodian or hospital name that manages this document. static string document document file. static string health_data_type data type name for health document. static string id document id. static string patient patient name. static string patient_birthdate patient birth date with the yyyymmdd format. static string patient_gender gender code of the patient. static string title document title. static string type document type. static int type_cda cda (hl7 clinical document architecture) type. static int type_pdf pdf (portable document format) type. fields inherited from interface com.samsung.android.sdk.healthdata.healthconstants.discretemeasurement start_time, time_offset fields inherited from interface com.samsung.android.sdk.healthdata.healthconstants.common create_time, custom, device_uuid, package_name, update_time, uuid field detail type static final string type document type. mandatory type: int available values: one of the following values type_cda type_pdf since: 1.3.0 see also: constant field values type_cda static final int type_cda cda (hl7 clinical document architecture) type. its constant value is 1. since: 1.3.0 see also: type, constant field values type_pdf static final int type_pdf pdf (portable document format) type. its constant value is 2. since: 1.3.0 see also: type, constant field values document static final string document document file. mandatory type: file since: 1.3.0 see also: constant field values id static final string id document id. mandatory type: string value length: 0 ~ 60 since: 1.3.0 see also: constant field values title static final string title document title. mandatory type: string since: 1.3.0 see also: constant field values patient static final string patient patient name. mandatory type: string since: 1.3.0 see also: constant field values patient_gender static final string patient_gender gender code of the patient. "m" indicates a male and "f" indicates a female. optional type: string value length: 0 ~ 1 available values: one of the following values "m" "f" since: 1.3.0 see also: constant field values patient_birthdate static final string patient_birthdate patient birth date with the yyyymmdd format. optional type: string value length: 0 ~ 8 since: 1.3.0 see also: constant field values author static final string author author or doctor name who write this document. optional type: string since: 1.3.0 see also: constant field values custodian static final string custodian custodian or hospital name that manages this document. mandatory type: string since: 1.3.0 see also: constant field values health_data_type static final string health_data_type data type name for health document. since: 1.3.0 see also: constant field values

      https://developer.samsung.com/health/android/data/api-reference/com/samsung/android/sdk/healthdata/HealthConstants.HealthDocument.html
      1. Develop
      2. Health

      api

      HealthDataResolver.UpdateRequest

      overview package class tree deprecated index com.samsung.android.sdk.healthdata interface healthdataresolver.updaterequest enclosing class: healthdataresolver public static interface healthdataresolver.updaterequest this interface is able to make a request to update health data for the specific health data type. request for updating data healthdataresolver.update() helps that your application updates samsung health's existing data. the following information is mandatory to build an updaterequest instance. mandatory information description data type set the data type with: updaterequest.builder.setdatatype() data update set data to update with: updaterequest.builder.sethealthdata() you can make a request instance with updaterequest.builder.build(). since: 1.0.0 nested class summary nested classes modifier and type interface and description static class healthdataresolver.updaterequest.builder this class is a builder to configure healthdataresolver.updaterequest.

      https://developer.samsung.com/health/android/data/api-reference/com/samsung/android/sdk/healthdata/HealthDataResolver.UpdateRequest.html
      No Search Results
      No Search results. Try using another keyword.
      • <<
      • <
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • >
      • >>
      Samsung Developers
      Samsung Developers
      Quick Link
      • Android USB Driver
      • Code Lab
      • Galaxy Emulator Skin
      • Foldables and Large Screens
      • One UI Beta
      • Remote Test Lab
      • Samsung Developers Podcast
      Family Site
      • Bixby
      • Knox
      • Samsung Pay
      • SmartThings
      • Tizen
      • Samsung Research
      • SamsungOpen Source
      • Samsung Dev Spain
      • Samsung Dev Brazil
      Legal
      • Terms
      • Privacy
      • Open Source License
      • Cookie Policy
      Social Communications
      • Facebook
      • Instagram
      • Twitter
      • YouTube
      • Buzzsprout
      • Rss
      • Linkedin
      • System Status
      • Site Map
      • System Status
      • Site Map
      • facebook
      • instagram
      • twitter
      • youtube
      • buzzsprout
      • rss
      • linkedin

      Copyright © 2023 SAMSUNG. All rights reserved.