Android (Kotlin)
Utility functions
isHealthConnectAvailable
Checks if Health Connect is available in a given application/activity context
fun isHealthConnectAvailable(context: Context): Booleancontext: Context-> Activity context from android app to check if Health Connect is available for
openHealthConnect
Opens a health connect activity to overlay the current one, effectively redirecting the user into the Health Connect app
fun openHealthConnect(context: Context): Unitcontext: Context: Activity context from android app
Initialization of Terra manager
instance
fun instance(devId: String, referenceId: String?,
context: Context,
completion: (TerraManager, TerraError?) -> Unit)devId: String➡ The developer identifier given to your after you signed up on TerrareferenceId: String?➡ This is used by you to identify a user from your server to a terra usercontext: Context➡ The context from the activity you are instantiating fromcompletion: @escaping (TerraManager, TerraError?) -> Void➡ A callback function that is called when the TerraManager class is initialised. If an error has occurred in creation, then the completion will return aTerraErrorclass. Highly recommended to wait for this callback before proceeding
Terra manager Instance methods
Connection setup/management
allGivenPermissions
Retrieves all given permissions granted by health connect
fun allGivenPermissions(completion: (Set<String>) -> Unit)completion (Set<String>) -> Unit-> A set of given permissions to Health Connect
initConnection
Initialises a connection for Samsung Health/Google Fit
fun initConnection(connection: Connections,
token: String,
context: Context,
customPermissions: Set<CustomPermissions> = setOf(),
schedulerOn: Boolean = true,
startIntent: String? = null,
completion: (Boolean, TerraError?) -> Unit = { _, _ -> })type: Connections➡ An ENUM from the Connections class signifying the connection you wish to initiate for.token: String➡ A token used for authentication. Generate one here: https://docs.tryterra.co/reference/generate-authentication-token(Optional)
customReadTypes: Set<CustomPermissions>➡ This is defaulted as an emptySet. If you want to make a more granular permissions request, you may send us a set ofCustomPermissionscontext: Context➡ The context from the activity you are instantiating fromschedulerOn: Bool➡ A boolean dictating if you wish turn on the schduler. Defaults to true.startIntent: String?➡ The path to the activity you wish to display when the user scans a freestylelibre from the background (i.e "co.tryterra.terra.example.MainActivity")completion: @escaping (Bool, TerraError?) -> Void➡ A callback with a boolean dictating if the initialisation succeeds.
getUserId
fun getUserId(type: Connections): String?type: Connections➡ The connection to retrieve the userId for
Data Retrieval
getActivity
fun getActivity(type: Connections,
startDate: Date,
endDate: Date,
toWebhook: Boolean = true,
completion: (Boolean, TerraActivityDataPayload?, TerraError?) -> Unit = {_, _, _ ->})type: Connections➡ The Connection to get data fromstartDate: DateorstartDate: Long➡ The beginning of the request in either Date or Unix TimestampendDate: DateorendDate: Long➡ The end of the request in either Date or Unix TimestamptoWebhook: Bool➡ Whether or not to send data to your webhook`completion: (Bool, TerraActivityDataPayload?, TerraError?) -> Void ➡
Bool -> If the request was successful or not. If not, a TerraError instance will also be called
TerraActivityDataPayload? -> A payload for each data type. If toWebhook is set to true, this returns a class with a property reference referring to the payload reference sent to your webhook. If toWebhook is set to false, then this returns the entire Terra normalised payload.
TerraError? -> Returned if any error occurred while retrieving data
getDaily
fun getDaily(type: Connections,
startDate: Date,
endDate: Date,
toWebhook: Boolean = true,
completion: (Boolean, TerraDailyDataPayload?, TerraError?) -> Unit = {_, _, _ ->})type: Connections➡ The Connection to get data fromstartDate: DateorstartDate: Long➡ The beginning of the request in either Date or Unix TimestampendDate: DateorendDate: Long➡ The end of the request in either Date or Unix TimestamptoWebhook: Bool➡ Whether or not to send data to your webhook`completion: (Bool, TerraDailyDataPayload?, TerraError?) -> Void ➡
Bool -> If the request was successful or not. If not, a TerraError instance will also be called
TerraDailyDataPayload? -> A payload for each data type. If toWebhook is set to true, this returns a class with a property reference referring to the payload reference sent to your webhook. If toWebhook is set to false, then this returns the entire Terra normalised payload.
TerraError? -> Returned if any error occurred while retrieving data
getSleep
fun getSleep(type: Connections,
startDate: Date,
endDate: Date,
toWebhook: Boolean = true,
completion: (Boolean, TerraSleepDataPayload?, TerraError?) -> Unit = {_, _, _ ->})type: Connections➡ The Connection to get data fromstartDate: DateorstartDate: Long➡ The beginning of the request in either Date or Unix TimestampendDate: DateorendDate: Long➡ The end of the request in either Date or Unix TimestamptoWebhook: Bool➡ Whether or not to send data to your webhook`completion: (Bool, TerraSleepDataPayload?, TerraError?) -> Void ➡
Bool -> If the request was successful or not. If not, a TerraError instance will also be called
TerraSleepDataPayload? -> A payload for each data type. If toWebhook is set to true, this returns a class with a property reference referring to the payload reference sent to your webhook. If toWebhook is set to false, then this returns the entire Terra normalised payload.
TerraError? -> Returned if any error occurred while retrieving data
getNutrition
fun getNutrition(type: Connections,
startDate: Date,
endDate: Date,
toWebhook: Boolean = true,
completion: (Boolean, TerraNutritionDataPayload?, TerraError?) -> Unit = {_, _, _ ->})type: Connections➡ The Connection to get data fromstartDate: DateorstartDate: Long➡ The beginning of the request in either Date or Unix TimestampendDate: DateorendDate: Long➡ The end of the request in either Date or Unix TimestamptoWebhook: Bool➡ Whether or not to send data to your webhook`completion: (Bool, TerraNutritionDataPayload?, TerraError?) -> Void ➡
Bool -> If the request was successful or not. If not, a TerraError instance will also be called
TerraNutritionDataPayload? -> A payload for each data type. If toWebhook is set to true, this returns a class with a property reference referring to the payload reference sent to your webhook. If toWebhook is set to false, then this returns the entire Terra normalised payload.
TerraError? -> Returned if any error occurred while retrieving data
Was this helpful?