{"id":26178854,"url":"https://github.com/patloew/rxfit","last_synced_at":"2025-10-08T20:06:01.837Z","repository":{"id":128808772,"uuid":"53169994","full_name":"patloew/RxFit","owner":"patloew","description":"🏃Reactive Fitness API Library for Android and RxJava","archived":false,"fork":false,"pushed_at":"2017-04-18T22:39:39.000Z","size":248,"stargazers_count":216,"open_issues_count":3,"forks_count":17,"subscribers_count":9,"default_branch":"2.x","last_synced_at":"2025-04-14T22:33:47.248Z","etag":null,"topics":["android","fit","google-fit","google-play-services","googleapiclient","rxjava","rxjava2"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/patloew.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-03-04T22:36:47.000Z","updated_at":"2023-09-08T17:07:46.000Z","dependencies_parsed_at":"2023-04-20T16:33:36.661Z","dependency_job_id":null,"html_url":"https://github.com/patloew/RxFit","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/patloew/RxFit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patloew%2FRxFit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patloew%2FRxFit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patloew%2FRxFit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patloew%2FRxFit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patloew","download_url":"https://codeload.github.com/patloew/RxFit/tar.gz/refs/heads/2.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patloew%2FRxFit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000701,"owners_count":26082819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","fit","google-fit","google-play-services","googleapiclient","rxjava","rxjava2"],"created_at":"2025-03-11T21:47:25.864Z","updated_at":"2025-10-08T20:06:01.797Z","avatar_url":"https://github.com/patloew.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Reactive Fit API Library for Android\n\n[![Build Status](https://travis-ci.org/patloew/RxFit.svg?branch=2.x)](https://travis-ci.org/patloew/RxFit) [![codecov](https://codecov.io/gh/patloew/RxFit/branch/2.x/graph/badge.svg)](https://codecov.io/gh/patloew/RxFit/branch/2.x) [ ![Download](https://api.bintray.com/packages/patloew/maven/RxFit2/images/download.svg) ](https://bintray.com/patloew/maven/RxFit2/_latestVersion) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-RxFit-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/3252) [![API](https://img.shields.io/badge/API-9%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=9)\n\nThis library wraps the Fit API in [RxJava 2](https://github.com/ReactiveX/RxJava/tree/2.x) Observables and Singles. No more managing GoogleApiClients! Also, the authorization process for using fitness data is handled by the lib.\n\nSee the [1.x branch](https://github.com/patloew/RxFit/tree/1.x) for a RxJava 1 version of this library.\n\n# Usage\n\nCreate an RxFit instance once, preferably in your Application's `onCreate()` or by using a dependency injection framework. Make sure to include all the APIs and Scopes that you need for your app. The RxFit class is very similar to the Fitness class provided by the Fit API. Instead of `Fitness.HistoryApi.readData(apiClient, dataReadRequest)` you can use `rxFit.history().read(dataReadRequest)`. Make sure to have the Location and Body Sensors permission from Marshmallow on, if they are needed by your Fit API requests. If the user didn’t already authorize your app for using fitness data, the lib handles showing the authorization dialog.\n\nExample:\n\n```java\n// Create one instance and share it\nRxFit rxfit = new RxFit(\n        context,\n        new Api[] { Fitness.HISTORY_API },\n        new Scope[] { new Scope(Scopes.FITNESS_ACTIVITY_READ) }\n);\n\nDataReadRequest dataReadRequest = new DataReadRequest.Builder()\n\t    .aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)\n\t    .aggregate(DataType.TYPE_CALORIES_EXPENDED, DataType.AGGREGATE_CALORIES_EXPENDED)\n\t    .bucketBySession(1, TimeUnit.MINUTES)\n\t    .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)\n\t    .build();\n\nrxFit.history().read(dataReadRequest)\n        .flatMapObservable(dataReadResult -\u003e Observable.from(dataReadResult.getBuckets()))\n        .subscribe(bucket -\u003e {\n        \t/* do something */\n        });\n```\n\nAn `RxFitOnExceptionResumeNext` Transformer is available in the lib, which resumes with another Single/Observable when an Exception is thrown, except when the exception was a GoogleAPIConnectionException which was caused by an unresolved resolution.\n\nAn optional global default timeout for all Fit API requests made through the library can be set via `rxFit.setDefaultTimeout(...)`. In addition, timeouts can be set when creating a new Observable by providing timeout parameters, e.g. `rxFit.history().read(dataReadRequest, 15, TimeUnit.SECONDS)`. These parameters override the default timeout. When a timeout occurs, a StatusException is provided via `onError()`. The RxJava timeout operators can be used instead, but these do not cancel the Fit API request immediately.\n\nIf you don't want the library to automatically handle resolutions (e.g. for usage in a background service), you can disable this behavior when creating an RxFit instance by passing in `false` to the `handleResolutions` parameter: `new RxFit(ctx, apiArray, scopeArray, false)`.\n\nYou can also obtain a `Single\u003cGoogleApiClient\u003e`, which connects on subscribe and disconnects on unsubscribe via `GoogleAPIClientSingle.create(...)`.\n\nThe following Exceptions are thrown in the lib and provided via `onError()`:\n\n* `StatusException`: When the call to the Fit API was not successful or timed out\n* `GoogleAPIConnectionException`: When connecting to the GoogleAPIClient was not successful and the resolution (if available) was also not successful (e.g. when the user does not authorize your app to use fitness data). Resolutions are not handled when using `GoogleAPIClientObservable`.\n* `GoogleAPIConnectionSuspendedException`: When the GoogleApiClient connection was suspended.\n* `SecurityException`: When you try to call a Fit API without proper permissions.\n\n# Sample\n\nA basic sample app is available in the `sample` project. You need to create an OAuth 2.0 Client ID for the sample app, see the [guide in the Fit API docs](https://developers.google.com/fit/android/get-api-key).\n\n# Setup\n\nThe lib is available on jCenter. Add the following to your `build.gradle`:\n\n\tdependencies {\n\t    compile 'com.patloew.rxfit:rxfit2:2.0.1'\n\t}\n\n# Testing\n\nWhen unit testing your app's classes, RxFit behavior can be mocked easily. See the `MainPresenterTest` in the `sample` project for an example test.\n\n# Credits\n\nThe code for managing the GoogleApiClient is taken from the [Android-ReactiveLocation](https://github.com/mcharmas/Android-ReactiveLocation) library by Michał Charmas, which is licensed under the Apache License, Version 2.0.\n\n# License\n\n\tCopyright 2016 Patrick Löwenstein\n\n\tLicensed under the Apache License, Version 2.0 (the \"License\");\n\tyou may not use this file except in compliance with the License.\n\tYou may obtain a copy of the License at\n\n\t    http://www.apache.org/licenses/LICENSE-2.0\n\n\tUnless required by applicable law or agreed to in writing, software\n\tdistributed under the License is distributed on an \"AS IS\" BASIS,\n\tWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n\tSee the License for the specific language governing permissions and\n\tlimitations under the License.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatloew%2Frxfit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatloew%2Frxfit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatloew%2Frxfit/lists"}