connectGoogleHealthConnect

abstract suspend fun connectGoogleHealthConnect(context: Any, deviceId: String): SmartWalkingProfile

Android primary setup flow — requests Health Connect permissions and registers the device.

This is the recommended entry point for Android consumers. It:

  1. Checks Health Connect permissions; if not granted, requests them.

  2. Calls registerUser with DeviceType.HEALTH_CONNECT.

  3. If registration succeeds, enables auto-sync automatically.

If the user denies Health Connect permissions, returns a profile with isConnected = false without throwing.

Platform: Android only. On iOS, use connectAppleHealthKit.

Kotlin

lifecycleScope.launch {
try {
val profile = AFCore.smartWalking().connectGoogleHealthConnect(
context = this@MainActivity,
deviceId = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
)
if (profile.isConnected) {
showMessage("Health Connect connected — auto-sync enabled")
} else {
showMessage("Health Connect permissions denied")
}
} catch (e: Exception) {
showError("Health Connect error: ${e.message}")
}
}

Return

A SmartWalkingProfile reflecting the registration state. isConnected = false if permissions were denied.

Parameters

context

Android Context (Activity or Application) — needed to launch the Health Connect permission UI.

deviceId

A stable device identifier (e.g. ANDROID_ID).

Throws

on network or server errors (not on permission denial).