Add Vital SDKs as dependencies
Integrate with Vital Mobile SDK Authentication
Configure Health SDK and ask user for read permissions
VitalResource
s which you have asked permissions from your user for. If you
did not ask for permissions, data sync would not occur.[Optional] Customize the Foreground Service notification
[Optional] Configure Background Sync
AndroidManifest.xml
) must declare all the read or write permissions for all the data types you intend to sync.
For example, if you intend to sync Blood Pressure records and Blood Glucose reocrds, your app manifest must contain the following
<uses-permission>
declarations:
SDK VitalResource type | Read permissions required |
---|---|
Profile | android.permission.health.READ_HEIGHT |
Body | android.permission.health.READ_BODY_FAT android.permission.health.READ_WEIGHT |
Workout | android.permission.health.READ_EXERCISE android.permission.health.READ_HEART_RATE android.permission.health.READ_RESPIRATORY_RATE android.permission.health.READ_DISTANCE android.permission.health.READ_ACTIVE_CALORIES_BURNED android.permission.health.READ_ELEVATION_GAINED android.permission.health.READ_POWER android.permission.health.READ_SPEED |
Activity | android.permission.health.READ_ACTIVE_CALORIES_BURNED android.permission.health.READ_BASAL_METABOLIC_RATE android.permission.health.READ_TOTAL_CALORIES_BURNED android.permission.health.READ_DISTANCE android.permission.health.READ_STEPS android.permission.health.READ_FLOORS_CLIMBED android.permission.health.READ_DISTANCE android.permission.health.READ_VO2_MAX |
Sleep | android.permission.health.READ_SLEEP android.permission.health.READ_HEART_RATE android.permission.health.READ_RESPIRATORY_RATE android.permission.health.READ_HEART_RATE_VARIABILITY android.permission.health.READ_OXYGEN_SATURATION android.permission.health.READ_RESTING_HEART_RATE |
Glucose | android.permission.health.READ_BLOOD_GLUCOSE |
BloodPressure | android.permission.health.READ_BLOOD_PRESSURE |
HeartRate | android.permission.health.READ_HEART_RATE |
Steps | android.permission.health.READ_STEPS |
ActiveEnergyBurned | android.permission.health.READ_ACTIVE_CALORIES_BURNED |
BasalEnergyBurned | android.permission.health.READ_ACTIVE_CALORIES_BURNED android.permission.health.READ_BASAL_METABOLIC_RATE android.permission.health.READ_TOTAL_CALORIES_BURNED |
Water | android.permission.health.READ_HYDRATION |
shortService
Foreground Services declarations
into your AndroidManifest.xml. You need not modify your app’s Manifest to enable this.
SyncOnExactAlarmService
. The merged AndroidManifest.xml of your app
would include both of them.ActivityResultContract
created by Vital Health createPermissionRequestContract()
, you must launch
the contract using AndroidX Activity Result API.Attempts to launch the contract manually via the legacy Activity.startActivityForResult
API would result in an android.content.ActivityNotFoundException
exception on Android 14 and later.Item | Copy |
---|---|
Notification Title | Health Data Sync |
Notification Content | {APP_NAME} is synchronizing with Health Connect… |
Channel Title | Health Data Sync |
Channel Description | Notifies when {APP_NAME} is synchronizing with Health Connect. |
SyncNotificationBuilder
through VitalHealthConnectManager.syncNotificationBuilder
.You should register it as soon as your app process is created. One way to ensure this is through the AndroidX Startup
library. You can define an Initializer
of your own that depends on the SDK VitalHealthConnectInitializer
.SyncNotificationBuilder
implementationSCHEDULE_EXACT_ALARM
) requires a runtime permission request from the user.
More specifically:
USE_EXACT_ALARM
permission was introduced. This permits your app to
schedule Exact Alarms without interactive permission requests.
USE_EXACT_ALARM
attracts scrutiny during Google Play Store review. Per the Google Play Exact alarm permission policy:USE_EXACT_ALARM is a restricted permission and apps must only declare this permission if their core functionality supports the need for an exact alarm. Apps that request this restricted permission are subject to review, and those that do not meet the acceptable use case criteria will be disallowed from publishing on Google Play. (excerpted on 20 March 2024)If you choose to incorporate
USE_EXACT_ALARM
, you should prepare to justify to Google Play Store:SCHEDULE_EXACT_ALARM
is non-optimal to your product experience.Android OS | API Level | Requirements |
---|---|---|
Android 11 or below | <=30 | No interactive permission request. |
Android 12 | 31, 32 | SCHEDULE_EXACT_ALARM : Requires a runtime permission request. Revokable. |
Android 13 and above | >=33 | App must declare either:
|
uses-permission
claims:
USE_EXACT_ALARM
in the second tab.enableBackgroundSyncContract()
(an AndroidX ActivityResultContract
).If the runtime requires an interactive permission request, this contract will launch
an Android Intent to request the “Alarms & Reminders” permission. The contract result is a boolean, indicating whether
or not the Background Sync has been enabled successfully. For example, if the user did not grant the permission during the said Android Intent,
the contract returns false
.Otherwise, the contract returns true
synchronously when no user interaction is required.You must launch this ActivityResultContract
either through the in-built Android Compose support, or
through the AndroidX Activity Result API if you do not use Android Compose.You can also inspect if Background Sync has been enabled through the isBackgroundSyncEnabled
property.disableBackgroundSync()
method.You can also inspect if Background Sync has been disabled through the isBackgroundSyncEnabled
property.signOut()
a user, Vital SDK will automatically disable Background Sync.