Mobile SDKs

SpikeSDK Android (v3)

Current Android(Kotlin) SDK Version: 4.0.22

Android Package Package can be found here

Requirements

Android 9.0+ (Level 28, P, Pie)

Setup Guide

To add the SDK to your project, you have to add the following to your project's build.gradle file in the repositories block.

Text


After that, add the following to your app's build.gradle file in the dependencies block.

Text


Android permissions

Include the necessary health permissions in your AndroidManifest.xml to fully leverage the Spike SDK and access data from apps integrated with Health Connect. Please refer to this guide for details on the required permissions.

Note: Only request permissions essential to your app’s functionality. Requesting unused permissions may lead to Play Store rejections.

XML


Add an intent filter to your activity definition so that you can request the permissions at runtime.

XML


To handle Android 14 you also need to add activity-alias to your AndroidManifest.xml It is just a wrapper for the activity that requests permissions so no real activity is necessary.

XML


Spike SDK Usage

Step 1 - Create Spike connection

To set up the Spike SDK create SpikeConnectionV3 instance with your Spike application id, auth token and user id unique to each of your users:

Kotlin


Step 2 - Ask user for permissions

If you want to read data from Android Health Connect, you have to ensure user gives your app permissions. First, you have to check if Health Connect is available on users phone:

Kotlin


where

Kotlin


If update is required, you can use Spike helper to open Play Store for user to install Health Connect:

Kotlin


If Health Connect is installed, you can get permissions that are needed and a list of already provided permissions:

Kotlin


If you have missing permissions you can ask Android to present user with a modal asking user for permission to read the data. Example for Compose:

Kotlin

  • Please note that users might only grant partial permissions. In such cases, it’s up to you to decide whether your app can function effectively with limited access. The SpikeSDK itself will still operate even without full permissions; however, it may result in no data being returned in certain scenarios. Conversely, if your app has been granted additional permissions beyond the minimum required for specific data types, we may enhance certain entries by incorporating data sourced from other types (e.g., identifying manually entered data).

You can now use StatisticsFilter(providers = listOf(Provider.HEALTH_CONNECT)) to specifically retrieve data from Health Connect. Alternatively, you can omit the providers parameter entirely and allow Spike to choose the most suitable data source based on your request.

Step 3 - Get data

Info: The maximum permitted date range is 90 days There are two types of data you can retrieve from Spike:

  • Records consist of the raw data points collected from user devices or applications.
  • Statistics, on the other hand, are calculated values derived from records.

Statistics

Get daily statistics for steps and total distance from health Connect:

Kotlin


where:

Kotlin


Records

Get all records we have from Garmin provider:

Kotlin


where

Kotlin


Reading data

Statistics

Get daily statistics for steps and total distance from Garmin:

Kotlin


where:

Kotlin


Records

Get all records we have from Garmin provider:

Kotlin


where

Kotlin