Issue with Google Fit API on Android Wear

别说谁变了你拦得住时间么 提交于 2019-11-28 04:49:57

问题


I'm trying to implement the Google Fit API into my android wearable application. I have followed the GoogleFitAPI online steps with registering for an OAuth ID.

When trying to connect, I get an invalid account error.

Do I need to enable the free trial within the developer api console, or is there another issue that is causing this?

mClient = new GoogleApiClient.Builder(this)
            .addApi(Fitness.API)
            .addScope(Fitness.SCOPE_ACTIVITY_READ)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

回答1:


Actually the Fit API is available on Android Wear devices. But you still have to do the initial setup (Step 5) one time on a paired handheld device. Once you've logged in and displayed the consent screen on the phone, you can access the API from the watch. A recommendation would be to send the selected user account to the watch using the MessageAPI to avoid trying to connect to the API before the required information has been synced to the watch.

Please note that if you chose to access the API from the watch you will ONLY get data collected by the watch (data is synced from the watch to the phone and to the cloud, but not back to the watch).

An alternative solution is to fetch the fitness data from the phone and send it to the watch (again using the MessageAPI).

EDIT: As of Google Play Services 7.3.0 you can also use Fitness.HistoryApi.readDailyTotal() if you just want to get the daily total value. This doesn't require any authentication, but will also only give you data from the local device.




回答2:


Google Fit APIs are not yet enabled on Android Wear devices. You can connect to Google Fit on the handheld device and use the Wearable Data Layer to send data across, but obviously that uses the sensors and requires the use of a handheld device.



来源:https://stackoverflow.com/questions/28295189/issue-with-google-fit-api-on-android-wear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!