Connect
b.well Health SDK for Android
Connecting an On-Device Health Source
Overview
The connect method in the b.well SDK establishes an on-device health sync session for a given source, composing the underlying provisioning steps automatically. This is the recommended entry point for connecting an on-device health source — prefer it over calling setupMobileSync directly.
connect is called on BWellSdk.healthSync — BWellSdk.healthSync.connect() — the same object every other Health Sync method (requestPermissions, sync, disconnect) lives on.
Before calling connect, an on-device health source must be registered once at app startup via BWellHealthSync.configure(...).
Method Signature
suspend fun connect(sourceId: String? = null): BWellResult<Unit>sourceId: identifies which registered on-device source to start. In practice, omit this — callBWellSdk.healthSync.connect()with no arguments. There is currently only one supported on-device adapter (source id"health-connect"), which is auto-selected when nosourceIdis given. This parameter only matters if your app registers more than one on-device adapter at once, which isn't a real scenario today.BWellResult<Unit>: Indicates whether the connection was established successfully.
Under the Hood
connect composes 4 steps, none of which you need to call yourself:
- Resolves the target source (defaults to the one registered adapter).
- Maps that source's id to its backend connection identifier (e.g.
"health-connect"→"health_connect"). - Calls
setupMobileSyncfor that connection to provision backend credentials. - Maps those credentials into a session and hands it to the registered adapter to actually start syncing.
If credentials come back incomplete (e.g. missing an organization id), connect fails outright rather than starting a session with partial data.
Example Usage
var connectResult = BWellSdk.healthSync.connect()
if (!connectResult.success()) {
// Inspect connectResult.error for details, e.g. a session conflict
// with a different user already connected on this device
}Best Practices
- Call
disconnectbefore retryingconnectif the result indicates a session conflict. - Ensure the on-device health source has been configured at app startup before calling
connect.
Updated 12 days ago
