Android (Kotlin)

Utility functions

isHealthConnectAvailable

Checks if Health Connect is available in a given application/activity context

fun isHealthConnectAvailable(context: Context): Boolean
  • context: 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): Unit
  • context: 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 Terra

  • referenceId: String? ➡ This is used by you to identify a user from your server to a terra user

  • context: Context ➡ The context from the activity you are instantiating from

  • completion: @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 a TerraError class. 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 empty Set. If you want to make a more granular permissions request, you may send us a set of CustomPermissions

  • context: Context ➡ The context from the activity you are instantiating from

  • schedulerOn: 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 from

  • startDate: Date or startDate: Long ➡ The beginning of the request in either Date or Unix Timestamp

  • endDate: Date or endDate: Long ➡ The end of the request in either Date or Unix Timestamp

  • toWebhook: 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 from

  • startDate: Date or startDate: Long ➡ The beginning of the request in either Date or Unix Timestamp

  • endDate: Date or endDate: Long ➡ The end of the request in either Date or Unix Timestamp

  • toWebhook: 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 from

  • startDate: Date or startDate: Long ➡ The beginning of the request in either Date or Unix Timestamp

  • endDate: Date or endDate: Long ➡ The end of the request in either Date or Unix Timestamp

  • toWebhook: 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 from

  • startDate: Date or startDate: Long ➡ The beginning of the request in either Date or Unix Timestamp

  • endDate: Date or endDate: Long ➡ The end of the request in either Date or Unix Timestamp

  • toWebhook: 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?