Skip to main content
Version: Next

Android

Library that provides easy to use integration with Google Fit SDK. Used in Huma-Modules library for Heart Rate and Steps integrations.

Getting Started

To start working with google fit you need to create and 0Auth access registry for your project on [Google API console](https://developers.google.com/fit/android/get-api-key).

After obtaining key you can proceed with SDK.

  1. Check or get permission for specific type of activity.

    //returns true if access is granted for reading steps record
    HumaGoogleFitManager.getInstance().isAccessGranted(RecordType.Steps.Read)

    //opens screen where access can be given
    HumaGoogleFitManager.getInstance().requestAccess(context, RecordType.Steps.Read)

    //returns Intent for that screen
    HumaGoogleFitManager.getInstance().requestAccessIntent(context, RecordType.Steps.Read)

    Also you can observe for access if you have two or more points for starting some work with SDK

    HumaGoogleFitManager.getInstance().observeAccess(listOf(RecordType.Steps.Read)){
    //this callback will be called if user gave access for specified record types
    }
  2. After obtaining access to fitness data you can make a request:

    //suspend call for fitness data
    suspend fun HumaGoogleFitManager.fetchData(
    recordType = RecordType.Steps.Read
    startTime = Instant.now().minusDays(10)
    endTime = Instant.now(),
    bucketBy = BucketBy.Time(...), //optional
    enableServerQueries = true,
    tag = "Steps_Request", //optional
    timeout = Pair(10L, TimeUnit.SECONDS), //optional
    retryOnFailure = true //optional
    ) : List<Record>

    //callback version is also available
    fun HumaGoogleFitManager.fetchData(
    recordType = RecordType.Steps.Read
    startTime = Instant.now().minusDays(10)
    endTime = Instant.now(),
    bucketBy = BucketBy.Time(...), //optional
    enableServerQueries = true,
    tag = "Steps_Request", //optional
    timeout = Pair(10L, TimeUnit.SECONDS), //optional
    retryOnFailure = true //optional
    ) { records: List<Records> ->
    ...
    }

Documentation

API Reference