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
- Example
- Installing
- Readme
- Changelog
After obtaining key you can proceed with SDK.
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
}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> ->
...
}
Add the dependency in your local build.gradle file:
implementation("com.huma.sdk:google-fit:<latest-version>")
Initialize
HumaGoogleFitManager
in your Application class:HumaGoogleFitManager.init()
RecordType - specifiy data types and access level that need to be granted by the user.
Record - data point that is obtained from Google Fit SDK
BucketBy - type of bucketing that will be applied to user request
Huma Google Fit SDK support this listed record types:
- HeartRate
- Read
- Write
- Steps
- Read
- Write
- Sleep
- Read
- Write