简体   繁体   English

在Android Wear上访问Google Fit步骤

[英]Access Google Fit steps count on Android Wear

I'm working a face watch for Android Wear. 我正在为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. 另一个是可以访问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 我在这里找到了更多信息,但是有点旧: 访问Android Wear Fit数据

You can easily access the step count on the watch by using the Sensor API, using the Sensor.TYPE_STEP_COUNTER. 您可以使用Sensor.TYPE_STEP_COUNTER,使用Sensor API轻松访问手表上的步数。 More info here: 更多信息在这里:

http://developer.android.com/guide/topics/sensors/sensors_motion.html#sensors-motion-stepcounter 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. 从2015年开始,GoogleApis变得更易于使用。

To get daily total steps (same as in google fit) there is HistoryApi with it's method: 要获取每日总步数(与Google Fit中的步数相同),请使用HistoryApi及其方法:

Fitness.HistoryApi.readDailyTotal(googleApiClient, DataType.TYPE_STEP_COUNT_DELTA) ; 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). 顺便说一句,正如我记得阅读日常步骤一样,您不必要求任何范围(API权限)。

[Wear 1.0] [穿着1.0]

In wear 1.0 there is no google accounts support, thus all you can do is to use readDailyTotal() method. 在Wear 1.0中,没有Google帐户支持,因此您所能做的就是使用readDailyTotal()方法。 To make this work, you have to call useDefaultAccount() method while building your client. 要使其工作,必须在构建客户端时调用useDefaultAccount()方法。

[Wear 2.0] [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. 我不确定使用wear 1.0默认帐户的方法是否仍可以在wear 2.0设备上使用,但可以。 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登录 ,使用磨损帐户并不是一件容易的事;)只需按照上面链接中的步骤进行操作,就可以了。

Google Sign-In will provide you an Google account that you can use with GoogleApi clients. Google登录将为您提供一个可用于GoogleApi客户端的Google帐户。

One notice, when I used Google Developer Console to generate OAUTH configuration json file it did not work. 一条通知,当我使用Google Developer Console生成OAUTH配置json文件时,它不起作用。 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. 从Google API获取数据确实有点复杂。 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. 我最近帮助AliceOS正确设置了与Fit API的连接。 Perhaps the sample code mentioned in the comment could help you too. 注释中提到的示例代码也许也可以为您提供帮助。 It should at least be up to date. 它至少应该是最新的。 Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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