简体   繁体   中英

Access Google Fit steps count on Android Wear

I'm working a face watch for Android Wear. I want to read the steps which the watch counts (those displayed on the card). Are there any easy ways to access the data? My research showed that I can either create my own steps counter (which I don't want because of the accuracy problem). The other is do access the Google Api. However I find it very "weighty" on the code to implement it along side my phone battery function. Is there any other way to retrieve the data?

I don't want this to be connected with the phone app, but only with the one on the watch.

I found more info here but it is a bit old: Access Android Wear Fit Data

You can easily access the step count on the watch by using the Sensor API, using the Sensor.TYPE_STEP_COUNTER. More info here:

http://developer.android.com/guide/topics/sensors/sensors_motion.html#sensors-motion-stepcounter

Yet, it is an old question but maybe this answer will help someone in future. Since 2015 GoogleApis are a bit easier to use.

To get daily total steps (same as in google fit) there is HistoryApi with it's method:

Fitness.HistoryApi.readDailyTotal(googleApiClient, DataType.TYPE_STEP_COUNT_DELTA) ;

There is a blog post on reading daily steps . Some informations are also in Work with the Fitness History chapter, especially if you want to use data from other time ranges. By the way, as I remember to read daily steps you do not have to ask for any scopes (api permissions).

[Wear 1.0]

In wear 1.0 there is no google accounts support, thus all you can do is to use readDailyTotal() method. To make this work, you have to call useDefaultAccount() method while building your client.

[Wear 2.0]

I'm not sure whether the method with default account from wear 1.0 will still work on wear 2.0 devices but it's ok. Thanks Google Sign-In , using accounts on wear is not a pain ;) Just follow the steps in the link above and it should be good.

Google Sign-In will provide you an Google account that you can use with GoogleApi clients.

One notice, when I used Google Developer Console to generate OAUTH configuration json file it did not work. Just use the Sign-In site to create it.

Looks to me like you've done your research pretty well. Getting the data from the Google API is indeed a bit complicated. But if you don't want to create your own step counter, that's what you have to do. I recently helped AliceOS setting up the connection properly to the Fit API. Perhaps the sample code mentioned in the comment could help you too. It should at least be up to date. Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM