Flutter
Installation
Add the following to your pubspec.yaml
file in dependencies
:
heka_health: ^0.0.21
Setup
Google Fit
Note: Google fit is only supported on Android devices. If you have a use case for iOS, reach out to us and we will happily add the support.
Redirect URI needs to be set up so that the application is opened successfully post Google Auth. Make the following couple of changes to android/app/src/main/AndroidManifest.xml
file.
In application tag, add the following:
...
<application
...
...
# Add the line below
xmlns:tools="http://schemas.android.com/tools"
>
....
</application>
...
Now add the following activity inside the application and replace <YOUR_GOOGLE_CLIENT_ID>
with your google client id. Make sure this activity is not nested inside another activity. To get a client id, refer to our documentation on Google Fit setup.
<activity
android:name="net.openid.appauth.RedirectUriReceiverActivity"
android:exported="true"
tools:node="replace">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="com.googleusercontent.apps.<YOUR_GOOGLE_CLIENT_ID>"
/>
</intent-filter>
</activity>
There are other simpler ways to set up app redirect URLs, however, this method is recommended to support multiple redirect URLs for various platforms like Fitbit, Strava etc.
Apple Healthkit
Note: This is only supported on iOS (excluding iPads).
- Append the
Info.plist
with the following 2 entries:
<key>NSHealthShareUsageDescription</key>
<string>We will sync your data with the Apple Health app to give you better insights</string>
<key>NSHealthUpdateUsageDescription</key>
<string>We will sync your data with the Apple Health app to give you better insights</string>
Enabling HealthKit requires the following two steps in
Xcode
:- Go to the
Signing & Capabilities
tab of the Runner target's settings and add theHealthKit
capability. - Enable the background delivery option for
HealthKit
.
- Go to the
To make sure that health data is being synced even while on background, initialize the sync observers in
application:didFinishLaunchingWithOptions
method ofAppDelegate.swift
:
import HekaCore // Make sure you import HekaCore
// ...
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// ....
HekaManager().installObservers()
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
Usage
Import the package in the file you want to use the widget.
import 'package:heka_health/heka_health.dart';
Then use the widget using following lines.
HekaHealthWidget(
apiKey: '<YOUR_API_KEY_GOES_HERE>',
userUuid: '<YOUR_USER_UUID_GOES_HERE>',
);
To better understand api key
and user uuid
, please refer to the important concepts section.
APIs
isUserConnected
The SDK provides an API using which you can access whether a certain user is connected to a certain platform or not. This enables app developers to build UI components and nudge the user to connect if they haven't.
Future<bool> connected = isUserConnected(
key: '<YOUR_API_KEY_GOES_HERE>',
uuid: '<YOUR_USER_UUID_GOES_HERE>',
platformName: '<NAME_OF_PLATFORM>',
);
The possible platform names are:
google_fit
apple_healthkit
strava