Mobile SDKs

SpikeSDK Flutter (v3)

Current Flutter SDK Version: 4.2.24

Flutter Package can be found here

Example app can be found here

Requirements

iOS 13.0+ Android 9.0+ (Level 28, P, Pie)

Installation

Add ependency on SpikeSDK in your pubspec.yaml file:

YAML


iOS Setup Guide

Use pod install and pod update commands from ios/ folder of your app to install/update SpikeSDK.

iOS Signing & Capabilities

To add HealthKit support to your application's Capabilities.

  • Open the ios/ folder of your project in Xcode
  • Select the project name in the left sidebar
  • Open Signing & Capabilities section
  • In the main view select '+ Capability' and double click HealthKit

More details you can find here.

Info.plist

Add Health Kit permissions descriptions to your Info.plist file:

Text


Android Setup Guide

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

Text


Set Android SDK version in local.properties file:

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 will lead to app store rejection!

XML


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

XML


Check the contents of android/app/src/main/kotlin/{YOUR_PACKAGE_ID}/MainActivity.kt. You must see something like that in case it is the new app being developed:

Kotlin


You must change FlutterActivity to the FlutterFragmentActivity which means that your code should turn into the result similar to the one below:

Kotlin


In the Health Connect permissions activity, there is a link to your privacy policy. You need to grant the Health Connect app access in order to link back to your privacy policy. In the example below, you should either replace .MainActivity with an activity that presents the privacy policy or have the Main Activity route the user to the policy. This step may be required to pass Google app review when requesting access to sensitive permissions.

XML


Note: If permissions handling is not working, this might be related to launch mode being singleTop. This might be not needed, but some apps face problems when requesting permissions. If you face them, then you should try removing the following line:

XML


Note: If app is not building, it might be related to label replacement issue. In this case, you should add the following line:

XML

XML


Spike SDK Usage

Step 1 - Create Spike connection

Dart


Step 2 - ask user for permissions

If you plan to use Android Health Connect and/or Apple HealthKit data providers you should first get users permission to use their data:

Dart

  • 

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

Now you can read hourly statistics data of steps and distance for today:

Dart


where:

Dart


Records

Dart


where:

Dart


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.

iOS

Important notes about background delivery on iOS

  • For most data types the most possible frequency of updates is 1 hour.
  • iOS can update data more frequently for some data types, for example, vo2 max.
  • iOS may throttle the frequency of updates for background delivery depending on the app's activity, battery state, etc.
  • Background delivery is not possible while device is locked, so it will be executed only when the device is unlocked.
  • iOS may stop background delivery if it detects that the app is not active for a long time.
  • The feature is available starting with iOS 15.

Important: The SpikeSDK, along with any other HealthKit applications, cannot guarantee data synchronization on a fixed schedule. The hourly sync interval serves as a guideline rather than a strict requirement enforced by iOS. 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

Enable background delivery for app target

  • Open XCode with your ios project
  • Open the folder of your project in Xcode
  • Select the project name in the left sidebar
  • Open Signing & Capabilities section
  • Select HealthKit background delivery under HealthKit section

Initialization at app startup

For background delivery to work properly, you need to initialize the SpikeSDK at app startup.

AppDelegate.swift:

Swift


Android

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:

XML


Flutter specific

Add includeBackgroundDelivery: true when asking for permissions:

Dart


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

Now you can enable background delivery:

Dart


Keep in mind that calling enableBackgroundDelivery will overwrite previous configuration. So you have to call it with all the data types you want in one call.

To check current configuration call getBackgroundDeliveryConfig() method.

To stop background delivery call disableBackgroundDelivery() method.