简体   繁体   中英

Issue with Google Fit API on Android Wear

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();

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.

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.

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