Android (Kotlin)
Last updated
Was this helpful?
Last updated
Was this helpful?
First, initialize the TerraManager
class in the onCreate of your main activity
Terra
initializationTerra
should be initialized every time your app is started
This is a necessary prerequisite for other SDK functions to run as expected
To do this, run the as below:
Once Terra is initialized, you can create a Samsung Health/Google Fit connection.
initConnection
only needs to be run a single time. Health Connect prohibits the permission popup to appear more than once for any given permission, so calling initConnection
more than once will result in no action at all
The only case where it would re-appear is if:
you call initConnection with an expanded set of customPermissions
the app is deleted & reinstalled.
customPermissions
is used to customize the permissions list shown in the Apple Health popup when calling initConnection
. When empty, it defaults to all available permissions
To ensure a connection is still valid on the client side, use the terra.getUserid()
method. This function is synchronous and returns the user_id
right away or null if none exists.
Always use this method right after initializing Terra to see if the connection still exists,
if the connection exists, all is good! 🎉 keep vibing along
You may set toWebhook
to false if you wish for the callback function to return the data payload on the client side.
Run the on the terra
instance you created above to have the corresponding permission screen pop up.
if you expect the connection to exist, but returns null, call terra.initConnection to re-establish it. No permission screen will be shown again and the user flow will be unaffected
if it is expected for the connection to no longer exist, you may allow the user to re-connect if they so choose (you'd then call as before, but no permission screen would be shown)
In order to disconnect an SDK user, you may use , called from your backend
You can request for historical data using one of the .
Check out the for details about all the functions in the SDK
Health Connect installed on users' devices
Android 28 and above
Inside the dependencies section of your build.gradle
file, add the following line of code
You can find the latest version number on Maven Central.
Sync your project with Gradle by clicking on the "Sync Project with Gradle Files" button in the toolbar. This will download the TerraAndroid SDK and make it available to your project.
Give all permissions between the app you wish to read from (e.g. Samsung Health/Google Fit & Health Connect.
AndroidManifest.xml
Include the following tags under the Activity you wish to link the user to when they click the privacy policy link in the Health Connect permission screen:
Before going LIVE (release), you will need to apply for permissions to access the Health Connect API with Google. Use this application form.
For each permission which you are not using, please add the following lines to your AndroidManifest.xml
with android.permission.health.XXX
for each permission you aren't using
If you need to access Terra's Health & Fitness API, it is only secure to do so from your server backend and send the desired data to your mobile frontend.
Never expose your API key on the client side unless you are simply testing
token
is a single-use token created to ensure the authentication endpoint for creating a (and connecting the SDK to Terra's servers) does not get abused.
In order to generate it, place the call below on your server, and provide it to your client side using your own logic.
During the development phase, it it acceptable to place this call on the client side, exposing your API key in your mobile app.
For a production implementation, DO NOT expose your API key this way, and make sure to only make this call from your backend
Creates a token to be used with initConnection() functions in the Terra mobile SDKs in order to create a user record for Apple Health or Samsung Health (or equivalent)
/auth/generateAuthToken
your developer ID
testingTerra
your API key
OtHJok60oQmT8zhnUWc4SWBJI7ztPTs88C0gOsJJ