Mobile SDKs

SpikeSDK Android (v3)

Current Android(Kotlin) SDK Version: 4.2.32

Android Package Package can be found here (api reference)

Example app 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
XML extensive permissions


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


Backgrdound delivery

Background delivery ensures that data updates are sent to your backend via webhooks, even when the application is in the background or closed.

Important notes about background delivery on Android

  • Background delivery is scheduled to run every hour. But ultimately Android decides when the delivery will be executed.
  • Android may throttle the frequency of updates for background delivery depending on the app's activity, battery state, etc.
  • Android may stop background delivery if it detects that the app is not active for a long time.
  • There is a limit of queries that can be done in Health Connect and it is different for foreground and background reads, so please request only essential data to be delivered in background. More information on (Health Connect documentation)

Important: The SpikeSDK, along with any other applications, cannot guarantee data synchronization on a fixed schedule. The hourly sync interval serves as a guideline rather than a strict requirement enforced by Android. Consequently, the actual synchronization frequency may vary, occurring hourly, once per day, or during specific system-defined events, such as the conclusion of Sleep Mode or when the device begins charging.



Setup

Add the following permission to your AndroidManifest.xml:

Kotlin


Check if background delivery is possible with current Health Connect version:

Kotlin


If not, you can ask user to update Health Connect to the latest version.

Ask for background read permission:

Kotlin


You can also ask for background delivery permission in the same time as other permissions.

Now you can enable background delivery:

Kotlin


Keep in mind that calling enableBackgroundDeliverywill overwrite previous configuration. If you want to add more types, you have to call enableBackgroundDeliveryagain with updated configuration:

Kotlin


To check current configuration call getBackgroundDeliveryConfig()method.

To stop background delivery call disableBackgroundDelivery()method.

Reading logs

By default SPikeSDK logs are sent to standard Android Logcat. If for some reason you want to read them, you can use the following code (running it before you start using SpikeSDK):

Kotlin


If you are utilising Background Delivery, this code should be run in your application's onCreatemethod:

Kotlin


Also application should be set in AndroidManifest.xml:

Kotlin