app/src/main/java/com/google/android/gms/fit/samples/basichistoryapifinal/Update.java
private void buildFitnessClient() {
        if (mClient == null && checkPermissions()) {
            mClient = new GoogleApiClient.Builder(this)
                    .addApi(Fitness.SENSORS_API)
                    .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
                    .addConnectionCallbacks(
                            new GoogleApiClient.ConnectionCallbacks() {
                                @Override
                                public void onConnected(Bundle bundle) {
                                    Log.i(TAG, "Connected!!!");
                                    // Now you can make calls to the Fitness APIs.
                                    findFitnessDataSources();
                                }

                                @Override
                                public void onConnectionSuspended(int i) {
                                    // If your connection to the sensor gets lost at some point,
                                    // you'll be able to determine the reason and react to it here.
                                    if (i == GoogleApiClient.ConnectionCallbacks.CAUSE_NETWORK_LOST) {
                                        Log.i(TAG, "Connection lost.  Cause: Network Lost.");
                                    } else if (i
                                            == GoogleApiClient.ConnectionCallbacks.CAUSE_SERVICE_DISCONNECTED) {
                                        Log.i(TAG,
                                                "Connection lost.  Reason: Service Disconnected");
                                    }
                                }
                            }
                    )
                    .enableAutoManage(this, 0, new GoogleApiClient.OnConnectionFailedListener() {
                        @Override
                        public void onConnectionFailed(ConnectionResult result) {
                            Log.i(TAG, "Google Play services connection failed. Cause: " +
                                    result.toString());
                            Snackbar.make(
                                    Update.this.findViewById(R.id.main_activity_view),
                                    "Exception while connecting to Google Play services: " +
                                            result.getErrorMessage(),
                                    Snackbar.LENGTH_INDEFINITE).show();
                        }
                    })
                    .build();
        }
    }
/*
    Used for implementing the BuildClient for calling the SensorsAPI
     */
Used for implementing the BuildClient for calling the SensorsAPI
Used for implementing the BuildClient for calling the SensorsAPI
private void buildFitnessClient() {
        if (mClient == null && checkPermissions()) {
            mClient = new GoogleApiClient.Builder(this)
                    .addApi(Fitness.SENSORS_API)
                    .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
                    .addConnectionCallbacks(
                            new GoogleApiClient.ConnectionCallbacks() {
                                @Override
                                public void onConnected(Bundle bundle) {
                                    Log.i(TAG, "Connected!!!");
                                    findFitnessDataSources();
                                }
                                @Override
                                public void onConnectionSuspended(int i) {
                                    if (i == GoogleApiClient.ConnectionCallbacks.CAUSE_NETWORK_LOST) {
                                        Log.i(TAG, "Connection lost.  Cause: Network Lost.");
                                    } else if (i
                                            == GoogleApiClient.ConnectionCallbacks.CAUSE_SERVICE_DISCONNECTED) {
                                        Log.i(TAG,
                                                "Connection lost.  Reason: Service Disconnected");
                                    }
                                }
                            }
                    )
                    .enableAutoManage(this, 0, new GoogleApiClient.OnConnectionFailedListener() {
                        @Override
                        public void onConnectionFailed(ConnectionResult result) {
                            Log.i(TAG, "Google Play services connection failed. Cause: " +
                                    result.toString());
                            Snackbar.make(
                                    Update.this.findViewById(R.id.main_activity_view),
                                    "Exception while connecting to Google Play services: " +
                                            result.getErrorMessage(),
                                    Snackbar.LENGTH_INDEFINITE).show();
                        }
                    })
                    .build();
        }
    }
private void buildFitnessClient ( ) { if ( mClient == null && checkPermissions ( ) ) { mClient = new GoogleApiClient . Builder ( this ) . addApi ( Fitness . SENSORS_API ) . addScope ( new Scope ( Scopes . FITNESS_ACTIVITY_READ ) ) . addConnectionCallbacks ( new GoogleApiClient . ConnectionCallbacks ( ) { @ Override public void onConnected ( Bundle bundle ) { Log . i ( TAG , "Connected!!!" ) ; findFitnessDataSources ( ) ; } @ Override public void onConnectionSuspended ( int i ) { if ( i == GoogleApiClient . ConnectionCallbacks . CAUSE_NETWORK_LOST ) { Log . i ( TAG , "Connection lost.  Cause: Network Lost." ) ; } else if ( i == GoogleApiClient . ConnectionCallbacks . CAUSE_SERVICE_DISCONNECTED ) { Log . i ( TAG , "Connection lost.  Reason: Service Disconnected" ) ; } } } ) . enableAutoManage ( this , 0 , new GoogleApiClient . OnConnectionFailedListener ( ) { @ Override public void onConnectionFailed ( ConnectionResult result ) { Log . i ( TAG , "Google Play services connection failed. Cause: " + result . toString ( ) ) ; Snackbar . make ( Update . this . findViewById ( R . id . main_activity_view ) , "Exception while connecting to Google Play services: " + result . getErrorMessage ( ) , Snackbar . LENGTH_INDEFINITE ) . show ( ) ; } } ) . build ( ) ; } }
Used for implementing the BuildClient for calling the SensorsAPI
Used for implementing the BuildClient for calling the SensorsAPI
// Now you can make calls to the Fitness APIs. // If your connection to the sensor gets lost at some point, // you'll be able to determine the reason and react to it here.