@ovok/native/background-sync
Android background sync, the Bluetooth foreground service, sync notifications and background-safe storage.
- Stable unknown
- Release candidate since 1.16.1-rc.3
- Development since 1.16.1-dev.2111+9796905
Android background sync, the Bluetooth foreground service, sync notifications and background-safe storage.
Import from @ovok/native/background-sync.
Components
AndroidBluetoothForegroundService()
function AndroidBluetoothForegroundService(__namedParameters): Element;Keeps the Android Bluetooth foreground service running while enabled is true.
Parameters
| Parameter | Type |
|---|---|
__namedParameters | AndroidBluetoothForegroundServiceProps |
Returns
Element
Functions
cancelAndroidHealthConnectSync()
function cancelAndroidHealthConnectSync(): Promise<void>;Cancels the scheduled Health Connect sync.
Returns
Promise<void>
createBackgroundSafeClientStorage()
function createBackgroundSafeClientStorage(__namedParameters): BackgroundSafeClientStorage;Creates a storage adapter without importing expo-secure-store at module load time.
Parameters
| Parameter | Type |
|---|---|
__namedParameters | BackgroundSafeStorageOptions |
Returns
getPushNotificationPermission()
function getPushNotificationPermission(): Promise<PushNotificationPermissionStatus>;Reads the current notification permission without showing a prompt.
Returns
Promise<PushNotificationPermissionStatus>
isAndroidBatteryOptimizationIgnored()
function isAndroidBatteryOptimizationIgnored(): Promise<boolean>;Returns whether Android currently exempts the app from Doze battery optimizations.
Returns
Promise<boolean>
registerAndroidHealthConnectBackgroundTask()
function registerAndroidHealthConnectBackgroundTask(task, taskName?): void;Registers the JS entry point WorkManager invokes after process death. Call this once from the app entry point, not from a screen component, so it is registered before Android wakes the headless runtime.
Parameters
| Parameter | Type | Default value |
|---|---|---|
task | AndroidHealthConnectBackgroundTask | undefined |
taskName? | string | ANDROID_HEALTH_CONNECT_BACKGROUND_TASK |
Returns
void
requestAndroidBatteryOptimizationExemption()
function requestAndroidBatteryOptimizationExemption(): Promise<boolean>;Opens Android's consent screen for a Doze exemption. This is always explicit
opt-in. A false result means the exemption is not active yet; it can also
mean the app is not currently foregrounded, the user has already answered,
or the prompt was already shown. Recheck
isAndroidBatteryOptimizationIgnored after returning to the foreground.
Returns
Promise<boolean>
requestPushNotificationPermission()
function requestPushNotificationPermission(): Promise<PushNotificationPermissionStatus>;Requests notification permission. Call this while the app is in the foreground.
Returns
Promise<PushNotificationPermissionStatus>
runAndroidHealthConnectSync()
function runAndroidHealthConnectSync(__namedParameters): Promise<void>;Runs one Health Connect import without mounting React components.
Headless JS tasks have no React tree, so AndroidHealthSync cannot be rendered after the OS recreates the app process. The host app still restores its own client and patient identity, then calls this function with the same mapping it uses in the foreground.
Parameters
| Parameter | Type |
|---|---|
__namedParameters | AndroidHealthConnectSyncRunOptions |
Returns
Promise<void>
scheduleAndroidHealthConnectSync()
function scheduleAndroidHealthConnectSync(options?): Promise<void>;Schedules a WorkManager wake-up that starts the registered headless JS task. The task must create the host app's authenticated client and run the desired AndroidHealthSync service; the SDK cannot serialize a client or auth token.
Parameters
| Parameter | Type |
|---|---|
options? | AndroidHealthConnectBackgroundSyncOptions |
Returns
Promise<void>
showPushNotification()
function showPushNotification(__namedParameters): Promise<void>;Shows a local notification for a measurement delivered by the background queue.
Parameters
| Parameter | Type |
|---|---|
__namedParameters | PushNotificationContent |
Returns
Promise<void>
startAndroidBluetoothForegroundService()
function startAndroidBluetoothForegroundService(options?): Promise<void>;Starts the Android connected-device foreground service. Mount this alongside the BTProvider that owns the scan; the service keeps that app process alive while Android has the app in the background.
Parameters
| Parameter | Type |
|---|---|
options? | AndroidBluetoothForegroundServiceOptions |
Returns
Promise<void>
stopAndroidBluetoothForegroundService()
function stopAndroidBluetoothForegroundService(): Promise<void>;Stops the Android Bluetooth foreground service.
Returns
Promise<void>
Interfaces
AndroidBluetoothForegroundServiceOptions
Options of the Android Bluetooth foreground service.
Properties
AndroidHealthConnectBackgroundSyncOptions
Options of the scheduled Health Connect sync.
Properties
BackgroundSafeClientStorage
Async key-value storage backed by a SecureStore-compatible store.
Properties
BackgroundSafeSecureStore
A small storage adapter for values needed by a background relaunch.
The SDK deliberately does not own authentication or choose an app key. The host supplies a SecureStore-compatible implementation and may use this adapter for a session token, refresh token, or any other background-safe value.
Properties
BackgroundSafeStorageOptions
Options for createBackgroundSafeClientStorage.
Properties
| Property | Type | Description |
|---|---|---|
keychainAccessible? | number | Expo SecureStore.AFTER_FIRST_UNLOCK is numeric; pass that host constant when available. |
keychainService? | string | Keychain service name passed to the secure store on every call. |
keyListKey? | string | Used only for the adapter's internal key index; no application identity is assumed. |
secureStore | BackgroundSafeSecureStore | SecureStore-compatible store that persists the values. |
PushNotificationContent
Content of a local notification.
Properties
| Property | Type | Description |
|---|---|---|
body? | string | Notification body text. |
data? | Record<string, string | number | boolean | null> | Extra data delivered with the notification. |
title | string | Notification title. |
Type Aliases
AndroidHealthConnectBackgroundTask
type AndroidHealthConnectBackgroundTask = (input) => Promise<void>;Headless task invoked when the scheduled sync wakes the app.
Parameters
| Parameter | Type |
|---|---|
input | { reason?: string; } |
input.reason? | string |
Returns
Promise<void>
AndroidHealthConnectSyncRunOptions
type AndroidHealthConnectSyncRunOptions = object;Options of runAndroidHealthConnectSync.
Properties
chunkSize?
chunkSize?: number;Number of records sent per request.
client
client: Ovok;A restored, authenticated core client.
dataToSync
dataToSync: AndroidHealthSyncProps["dataToSync"];The same record-to-Observation mapping used by AndroidHealthSync.
onError?
onError?: (error) => void;Called when the import fails.
Parameters
| Parameter | Type |
|---|---|
error | Error |
Returns
void
onProgress?
onProgress?: (progress) => void;Called with the per-type sync progress.
Parameters
| Parameter | Type |
|---|---|
progress | Partial<Record<HealthSyncKey, SyncProgress>> |
Returns
void
patientId
patientId: string;The patient whose Health Connect records should be imported.
PushNotificationPermissionStatus
type PushNotificationPermissionStatus = "granted" | "denied" | "undetermined";Notification permission state.
Variables
ANDROID_HEALTH_CONNECT_BACKGROUND_TASK
const ANDROID_HEALTH_CONNECT_BACKGROUND_TASK: "OvokHealthConnectBackgroundSync" = "OvokHealthConnectBackgroundSync";Default name of the headless task that runs the Health Connect sync.
Last updated on