简体   繁体   中英

Android Wear access Google Fit API

I'm trying to access Google Fit API on Android Wear to get user Goals and I faced followed problem.

//I'm runing on Android Wear 2.0 emulator.

If there is no account specified (via setAccountName) in Builder, I get "Invalid Account" error message.

If i set manually account name I receive

"com.android.tools.fd.runtime.BootstrapApplication has problem with availability of google play services. Try again.".

I used following code to do this:

     mClient = new GoogleApiClient.Builder(this)
                    .addApi(Fitness.GOAL_API)
                    .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
                    .addScope(new Scope(Scopes.FITNESS_LOCATION_READ))
                    .addConnectionCallbacks([...])
                    .addOnConnectionFailedListener(
                        new GoogleApiClient.OnConnectionFailedListener() {
                            @Override
                            public void onConnectionFailed(ConnectionResult result) {
                                    if (result.hasResolution()) {
                                        try {
                             result.startResolutionForResult(ConfigAccount.this, request_code);
                                        } catch (IntentSender.SendIntentException e) {
                                            e.printStackTrace();
                                        }
                                    } else {
    GoogleApiAvailability.getInstance().getErrorDialog(ConfigAccount.this, result.getErrorCode(), request_code_error, new DialogInterface.OnCancelListener() {})
                    .build();

Every time the result.resolution in onConnectionFailed() is null. Error code is 5005 - UNKNOWN_AUTH_ERROR Because the resolution is null, the startResolutionOnResult and enableAutoManage does not work.

The credentials should be fine. Presented approach works on phone with Android 5.1.

Version of play services is 9.8.0. Downgrading the version didn't help.

Any Ideas how can I achieve my goal? Thanks.

From the FitnessStatusCodes documentation , the Error code is 5005 - UNKNOWN_AUTH_ERRO R is a status code denotes that an unknown error occurred while trying to obtain an OAuth token. So make sure you get your OAuth token properly.

Another possible cause of this error occurs if your app is not registered properly in google developer console.

It is stated in this thread that you might have registered app on Google developer Console using production keystore certificate fingerprint(SHA1) where as you are testing it on app which has debug keystore.

Here are the steps that you need to do.

  • Create one more client Id using debug keystore certificate fingerprint(SHA1).
  • Uninstall existing app.
  • Install app & connect to Google fit.
  • Check under google fit app & make sure that your app is listed as a connected app (... > Settings > Connected apps > Connected apps & devices

For more information, check this thread and this SO question .

I know it took some time to answer, but in Android Wear Dev Preview 4, Google added wear 2.0 authentication . It looks like other ways of login into google services are not supported on wearables.

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