How To Get Your Fitness Data From Google Fit? - Perficient Blogs
Blog
  • Topics
  • Industries
  • Partners

Explore

Topics

Industries

Partners

How To Get Your Fitness Data From Google Fit?

About Google Fit

“Google Fit is an open ecosystem that allows developers to upload fitness data to a central repository where users can access their data from different devices and apps in one location “. That means you can use your apps (not only Google Fit) or devices such as Apple Watch to upload your fitness data to the Google Fitness Store. You can also get your fitness data that you uploaded from the Store so you can do something else when you need it.

Before we can invoke methods from the Google Fit APIs, we have to connect to the appropriate fitness service, which are part of the Google Play services. The following APIs are available to us:                                                                       How To Get Your Fitness Data From Google Fit

What we always use are SensorsApi, RecordingApi and HistoryApi.

Sample overview

I did a sample project of getting fitness data from Google Fit, and show it in a line chart. As following, I get steps and weight in seven days from today. And these data were almost uploaded by Google Fit app, also I try to use my own app to upload steps data in sensor.                                                                                                                                                                   How To Get Your Fitness Data From Google Fit

Preparation

First, of course, you need a Google Account. Google Fit is available on Android devices with Google Play services 7.0 or higher. You should install the Google Play Service in your device, and then install the latest client library for Google Play services on your development host. Finally, get an OAuth 2.0 client ID for your Android applications.

How to begin with code

1.configure your project                            

 How To Get Your Fitness Data From Google Fit

2.uses-permission

if you want to use your own app to upload fitness data, you need to open your location service for sensor to collect data.

How To Get Your Fitness Data From Google Fit

3.ConnectionCallbacks      

4.OnConnectionFailedListener

How To Get Your Fitness Data From Google Fit

5.Create a GoogleApiClient

This client is used to subscribe steps data to Google Fit Store.

How To Get Your Fitness Data From Google Fit

You can change the Api and Scope attributes to do different things. For example, to get your weight data from the Store:

How To Get Your Fitness Data From Google Fit

6.Subscribe data

How To Get Your Fitness Data From Google Fit

7.Get your steps data from Google FitHow To Get Your Fitness Data From Google Fit

Then you can get your fitness data from the DataReadResult. If you want to show it in charts, you can get a third-party library to help you.

It’s not difficult to build a sample project if you refer to official documents, but we need to try harder to better understand it.

That’s all, hope you can give me your advice.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to the Weekly Blog Digest:

Sign Up

Categories