SpikeSDK Android (v3)
Current Android(Kotlin) SDK Version: 4.0.22
Android Package Package can be found here
Android 9.0+ (Level 28, P, Pie)
To add the SDK to your project, you have to add the following to your project's build.gradle file in the repositories block.
After that, add the following to your app's build.gradle file in the dependencies block.
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.
Add an intent filter to your activity definition so that you can request the permissions at runtime.
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.
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:
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:
where
If update is required, you can use Spike helper to open Play Store for user to install Health Connect:
If Health Connect is installed, you can get permissions that are needed and a list of already provided permissions:
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:
- 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.
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.
Get daily statistics for steps and total distance from health Connect:
where:
Get all records we have from Garmin provider:
where
Get daily statistics for steps and total distance from Garmin:
where:
Get all records we have from Garmin provider:
where