connect Google Health Connect
Android primary setup flow — requests Health Connect permissions and registers the device.
This is the recommended entry point for Android consumers. It:
Checks Health Connect permissions; if not granted, requests them.
Calls registerUser with DeviceType.HEALTH_CONNECT.
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
Android Context (Activity or Application) — needed to launch the Health Connect permission UI.
A stable device identifier (e.g. ANDROID_ID).
Throws
on network or server errors (not on permission denial).