Request Permissions

b.well Health SDK for Android

Requesting Health Data Permissions

Overview

The requestPermissions method in the b.well SDK requests user authorization for the specified health data types from the connected on-device health source. Call this after connect and before sync.

requestPermissions is called on BWellSdk.healthSyncBWellSdk.healthSync.requestPermissions(...) — the same object every other Health Sync method (connect, disconnect, sync) lives on.

Method Signature

suspend fun requestPermissions(types: Set<HealthDataType>, sourceId: String? = null): BWellResult<Unit>
  • types: The set of HealthDataType values to request permission for (e.g. ACTIVITY_SUMMARY, SLEEP, BLOOD_PRESSURE).
  • sourceId: identifies which registered on-device source to request permissions from. In practice, omit this — there's currently only one supported adapter, auto-selected.
  • BWellResult<Unit>: Indicates whether the permission request completed successfully — not whether the user actually granted the permissions (see Best Practices).

Under the Hood

requestPermissions doesn't own any UI itself. It maps each requested HealthDataType to the underlying Android Health Connect record types, then hands off to a permission-launching callback your app supplied when the on-device adapter was configured. That callback is what actually shows the OS permission dialog, since launching it requires an Activity, which the SDK deliberately doesn't hold a reference to.

Example Usage

val result = BWellSdk.healthSync.requestPermissions(HealthDataType.entries.toSet())
if (!result.success()) {
    // Inspect result.error for details
}

Best Practices

  • Request only the HealthDataType values your app actually needs.
  • Call this after a successful connect, before attempting to sync.
  • A successful result here means the request completed, not that every type was granted. A type the user denied doesn't fail here — it silently returns a FAILED count for that type later in sync. If a type is unexpectedly failing to sync, check its permission status first.

Did this page help you?