TerraSamsung Library was built on Android Studio Artic Fox with Kotlin 1.6 (jvmTarget 1.8). This package targets a minimum SDK version of 26 (Android OREO). This package makes use of the Health Platform API. Thus this package will only work with select Samsung Devices.
This library is intended for Android Developers wishing to connect their users to Terra through Samsung (Samsung Health). To use this package, please make sure the users have downloaded Health Platform on their devices and linked their Samsung Health Account to Health Platform. This can be done by going on Samsung Health -> Profile -> Settings -> Connected Services -> Health Platform and giving Health Platform access to their data.
Please download the .aar file from this repository and include it within the app/libs folder in your project structure. You may now add it as a dependency in your gradle configuration files. In your project level gradle file (build.gradle(:Project)), edit the repositories to include:
Then you must include the library and Health Platform API dependency in your app level gradle file(build.gradle(:app)) by adding the following line under dependencies:
You may now import classes from the library as: import co.tryterra.terra.*
Users will be prompted to give permissions to all the health data provided by Samsung Health. If the user does not give access to a certain datatype, the library will automatically request for access again when the data that requires that datatype is requested.
The requested permissions include: Location, Body Temperature, Respiratory Rate, Woman's Health, Heart Rate, Vo2Max, Activity, Personal Information, Sleep, Nutrition, Blood Pressure, Oxygen Saturation, and Blood Glucose.
The main classes you will need within this package is the Terra (co.tryterra.terra.Terra) and HealthStoreManager (co.tryterra.terra.HealthStoreManager) classes and the HealthDataClient (com.google.android.libraries.healthdata.HealthDataClient) and HealthDataService (com.google.android.libraries.healthdata.HealthDataService) classes from the Health Platform API.
To get started, initialize a HealthDataClient from the Health Platform API package giving it a context (ideally in your MainActivity file):
You can then initiaite a HealthStoreManager by:
and finally a Terra class by:
Upon initializaion, the Terra class will automatically connect to Terra and start pushing Body, Daily and Sleep data every 8 hours, while activity data every 20 minutes (the default according to our documentation.
If you wish to customize this timer, you can set it by passing the parameter bodySleepDailyTimer and activityTimerin milliseconds to the Terra class upon initialization.
The class also allows for manual querying of data.
The following functions will push data to your webhook URL from between the given startDate and endDate parameters:
The following function will push athlete data to your webhook URL. (No parameters required)
To deauthenticate users, you may run the following function:
This package also allows you to call the "authenticateUser" and "deauthenticateUser" endpoint along with the data request endpoints provided by Terra API.
The TerraAuth class deals with these two endpoints. First you have to initiate one:
and then call the following function with the Resource (GOOGLE, FITBIT, GARMIN, etc) as the argument:
Call back returns a JSONObject type.
Similarly for deauthentication, you can call the following function with the user ID as the argument:
To use the Terra API Data endpoints, you may do so with the TerraClient class:
Using this class, you can then request for data. The following example requests Body Data from our API with startDate and endDate parameters set as UNIX Timestamps in seconds. You may set "toWebhook" to false if you wish for the callback function to return the data payload.
The other data functions would be : getDaily, getActivity, getSleep , and getMenstruation`. These functions uses the same argument as the getBody function and all of them returns a callback with the response in JSONObject format. The toWebhook argument defaults to true if not provided.
Finally theres also getAthlete for which only accepts toWebhook argument.