Common | What are the benefits of Samsung Health SDK for Android?
Samsung Health app is a most popular health app and has more than 50 million of monthly active users. It works not only on Samsung smartphones but also non-Samsung phones if the device supports Android Marshmallow or above. It consists a big ecosystem including various health apps and connected accessory devices.
Samsung Health SDK for Android enables your app to manage the user’s health data with the unified interface by connecting to Samsung Health app. You can have more enhanced chances with a partnership of Samsung Health.
Common | I know the SDK needs Samsung Health installation. Can Samsung Health be installed to all phones? If not, how can I know the Samsung Health’s availability on the device?
Even though Samsung Health is installed in Android smartphones with Marshmallow or above including Samsung and non-Samsung smartphones, some phones cannot support Samsung Health. Its check code needs to be added to prevent a relevant situation.
The SDK’s Health Data provides a solution to check it through HealthConnectionErrorResult.hasResolution(). If the app meets the following cases, it means that the device is not available for Samsung Health.
HealthDataStore.connectService() gives a failure event.
You can set HealthConstants.Sleep's following properties including its own ones.
HealthConstants.Common.DEVICE_UUID
HealthConstants.SessionMeasurement.START_TIME
HealthConstants.SessionMeasurement.END_TIME
See the "Properties" description of each data type interface in API Reference for more information.
Sleep data can be set as the example shown below.
public class HealthDataExample {
// The state of connection
private HealthDataStore mStore;
private void insertSleepData(long start, long end, long offset) {
HealthDevice myDevice = new HealthDeviceManager(mStore).getLocalDevice();
HealthData data = new HealthData();
data.setSourceDevice(myDevice.getUuid());
// Fills all mandatory properties out
data.putLong(HealthConstants.Sleep.START_TIME, start);
data.putFloat(HealthConstants.Sleep.END_TIME, end);
data.putLong(HealthConstants.Sleep.TIME_OFFSET, offset);
HealthDataResolver resolver = new HealthDataResolver(mStore, null);
HealthDataResolver.InsertRequest insRequest
= new HealthDataResolver.InsertRequest.Builder()
.setDataType(HealthConstants.Sleep.HEALTH_DATA_TYPE)
.build();
// Do something
}
}
Health Data | There are two data types for steps. Which data type is better?
Handling all use cases for the phone and linked multi-accessory devices is not easy with it because the phone and accessory device like Galaxy Watch can provide step count data at the same time or not depending on how many devices are carried by the user.
Samsung Health SDK provides the following data types for steps:
Especially, its SOURCE_TYPE_ALL provides the day’s total steps simply without excluding duplicated steps when the user carries one more devices at the same time.
Getting real-time step count of the phone that Samsung Health is installed.
Health Data | The inserted health data’s measured time looks different. How can I solve it?
If new data is inserted to the health data store, CREATED_TIME, UPDATED_TIME of HealthConstants.Common are assigned by the system automatically. So you don’t need to set them separately. Data’s START_TIME or END_TIME indicates its UTC measurement time in milliseconds. Be careful not to set START_TIME or END_TIME as the device’s current local time.
TIME_OFFSET is indicated by the time zone and daylight saving time in milliseconds and it helps in showing the health data’s measured time properly in the device. The following example shows getting the current device’s TIME_OFFSET.
import java.util.TimeZone;
public class HeathDataExample {
long getTimeOffset(long intakeTime) {
return TimeZone.getDefault().getOffset(intakeTime);
}
}
Manage Your Cookies
We use cookies to improve your experience on our website and to show you relevant
advertising. Manage you settings for our cookies below.
Essential Cookies
These cookies are essential as they enable you to move around the website. This
category cannot be disabled.
Company
Domain
Samsung Electronics
.samsungdeveloperconference.com
Analytical/Performance Cookies
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.
Company
Domain
LinkedIn
.linkedin.com
Meta (formerly Facebook)
.samsungdeveloperconference.com
Google Inc.
.samsungdeveloperconference.com
Functionality Cookies
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.
Company
Domain
LinkedIn
.ads.linkedin.com, .linkedin.com
Advertising Cookies
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.
Company
Domain
LinkedIn
.linkedin.com
Meta (formerly Facebook)
.samsungdeveloperconference.com
Google Inc.
.samsungdeveloperconference.com
Preferences Submitted
You have successfully updated your cookie preferences.