void BuildFitnessClient()
        {
            var clientConnectionCallback = new ClientConnectionCallback();

            clientConnectionCallback.OnConnectedImpl = () => {
                SessionInsertRequest insertRequest = InsertFitnessSession();

                // [START insert_session]
                // Then, invoke the Sessions API to insert the session and await the result,
                // which is possible here because of the AsyncTask. Always include a timeout when
                // calling await() to avoid hanging that can occur from the service being shutdown
                // because of low memory or other conditions.
                Log.Info(TAG, "Inserting the session in the History API");
                var insertStatus = (Statuses)FitnessClass.SessionsApi.InsertSession(mClient, insertRequest).Await(1, TimeUnit.Minutes);

                // Before querying the session, check to see if the insertion succeeded.
                if (!insertStatus.IsSuccess)
                {
                    Log.Info(TAG, "There was a problem inserting the session: " +
                             insertStatus.StatusMessage);
                    return;
                }

                // At this point, the session has been inserted and can be read.
                Log.Info(TAG, "Session insert was successful!");
                // [END insert_session]

                // Begin by creating the query.
                var readRequest = ReadFitnessSession();

                // [START read_session]
                // Invoke the Sessions API to fetch the session with the query and wait for the result
                // of the read request.
                var sessionReadResult =
                    (SessionReadResult)FitnessClass.SessionsApi.ReadSession(mClient, readRequest).Await(1, TimeUnit.Minutes);

                // Get a list of the sessions that match the criteria to check the result.
                Log.Info(TAG, "Session read was successful. Number of returned sessions is: "
                         + sessionReadResult.Sessions.Count);
                foreach (Session session in sessionReadResult.Sessions)
                {
                    // Process the session
                    DumpSession(session);

                    // Process the data sets for this session
                    IList <DataSet> dataSets = sessionReadResult.GetDataSet(session);
                    foreach (DataSet dataSet in dataSets)
                    {
                        DumpDataSet(dataSet);
                    }
                }
            };

            // Create the Google API Client
            mClient = new GoogleApiClientBuilder(this)
                      .AddApi(FitnessClass.HISTORY_API)
                      .AddScope(new Scope(Scopes.FitnessActivityReadWrite))
                      .AddConnectionCallbacks(clientConnectionCallback)
                      .AddOnConnectionFailedListener(result => {
                Log.Info(TAG, "Connection failed. Cause: " + result);
                if (!result.HasResolution)
                {
                    // Show the localized error dialog
                    GooglePlayServicesUtil.GetErrorDialog(result.ErrorCode, this, 0).Show();
                    return;
                }
                // The failure has a resolution. Resolve it.
                // Called typically when the app is not yet authorized, and an
                // authorization dialog is displayed to the user.
                if (!authInProgress)
                {
                    try {
                        Log.Info(TAG, "Attempting to resolve failed connection");
                        authInProgress = true;
                        result.StartResolutionForResult(this,
                                                        REQUEST_OAUTH);
                    } catch (IntentSender.SendIntentException e) {
                        Log.Error(TAG,
                                  "Exception while starting resolution activity", e);
                    }
                }
            }).Build();
        }
 public Task InsertSessionAsync(SessionInsertRequest p0)
 {
     return(InsertSession(p0).AsAsync());
 }