@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

ParameterType
__namedParametersAndroidBluetoothForegroundServiceProps

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

ParameterType
__namedParametersBackgroundSafeStorageOptions

Returns

BackgroundSafeClientStorage


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

ParameterTypeDefault value
taskAndroidHealthConnectBackgroundTaskundefined
taskName?stringANDROID_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

ParameterType
__namedParametersAndroidHealthConnectSyncRunOptions

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

Returns

Promise<void>


showPushNotification()

function showPushNotification(__namedParameters): Promise<void>;

Shows a local notification for a measurement delivered by the background queue.

Parameters

ParameterType
__namedParametersPushNotificationContent

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

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

PropertyTypeDescription
notificationBody?stringText of the service notification body.
notificationTitle?stringText shown while the service keeps the BLE scan alive.
requestBatteryOptimizationExemption?booleanAsk Android to exempt this app from Doze when the service starts or returns to the foreground.

AndroidHealthConnectBackgroundSyncOptions

Options of the scheduled Health Connect sync.

Properties

PropertyTypeDescription
intervalMinutes?numberWorkManager's minimum supported interval is 15 minutes.
notificationBody?stringText of the sync notification body.
notificationTitle?stringTitle of the sync notification.
taskName?stringMust match the task name registered with register...Task.

BackgroundSafeClientStorage

Async key-value storage backed by a SecureStore-compatible store.

Properties

PropertyTypeDescription
clear() => Promise<void>Removes every key recorded in the index.
getItem(key) => Promise<string | null>Returns the stored value, or null when absent or unreadable.
reload() => Promise<void>Re-reads the key index after the device has completed first unlock.
removeItem(key) => Promise<void>Removes key and drops it from the index.
setItem(key, value) => Promise<void>Stores value under key and records the key in the index.

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

PropertyTypeDescription
deleteItemAsync?(key, options?) => Promise<void>Deletes the value under key; when omitted, removals only update the key index.
getItemAsync(key, options?) => Promise<string | null>Reads the value stored under key, or null when absent.
setItemAsync(key, value, options?) => Promise<void>Stores value under key.

BackgroundSafeStorageOptions

Options for createBackgroundSafeClientStorage.

Properties

PropertyTypeDescription
keychainAccessible?numberExpo SecureStore.AFTER_FIRST_UNLOCK is numeric; pass that host constant when available.
keychainService?stringKeychain service name passed to the secure store on every call.
keyListKey?stringUsed only for the adapter's internal key index; no application identity is assumed.
secureStoreBackgroundSafeSecureStoreSecureStore-compatible store that persists the values.

PushNotificationContent

Content of a local notification.

Properties

PropertyTypeDescription
body?stringNotification body text.
data?Record<string, string | number | boolean | null>Extra data delivered with the notification.
titlestringNotification title.

Type Aliases

AndroidHealthConnectBackgroundTask

type AndroidHealthConnectBackgroundTask = (input) => Promise<void>;

Headless task invoked when the scheduled sync wakes the app.

Parameters

ParameterType
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
ParameterType
errorError
Returns

void

onProgress?
onProgress?: (progress) => void;

Called with the per-type sync progress.

Parameters
ParameterType
progressPartial<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

On this page