Search code examples
androidwear-osgoogle-api-clientgoogle-fitandroid-wear-2.0

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.


Solution

  • 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.