예제 #1
0
        void BuildFitnessClient()
        {
            var clientConnectionCallback = new ClientConnectionCallback();

            clientConnectionCallback.OnConnectedImpl = () => Subscribe();
            // Create the Google API Client
            mClient = new GoogleApiClient.Builder(this)
                      .AddApi(FitnessClass.RECORDING_API)
                      .AddScope(new Scope(Scopes.FitnessActivityRead))
                      .AddConnectionCallbacks(clientConnectionCallback)
                      .AddOnConnectionFailedListener((ConnectionResult result) => {
                Log.Info(TAG, "Connection failed. Cause: " + result.ToString());
                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");
                        result.StartResolutionForResult(this, REQUEST_OAUTH);
                    } catch (IntentSender.SendIntentException e) {
                        Log.Error(TAG, "Exception while starting resolution activity", e);
                    }
                }
            }).Build();
        }
예제 #2
0
		void BuildFitnessClient ()
		{
			var clientConnectionCallback = new ClientConnectionCallback ();
            clientConnectionCallback.OnConnectedImpl = () => FindFitnessDataSources ();
			mClient = new GoogleApiClient.Builder (this)
				.AddApi (FitnessClass.SENSORS_API)
				.AddScope (new Scope (Scopes.FitnessLocationRead))
				.AddConnectionCallbacks (clientConnectionCallback)
				.AddOnConnectionFailedListener ((ConnectionResult result) => {
					Log.Info(TAG, "Connection failed. Cause: " + result);
					if (!result.HasResolution) {
						// Show the localized error dialog
						GooglePlayServicesUtil.GetErrorDialog (result.ErrorCode, this, 0).Show ();
								return;
					}
					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 ();
		}
예제 #3
0
		void BuildFitnessClient() {
			var clientConnectionCallback = new ClientConnectionCallback ();
			clientConnectionCallback.OnConnectedImpl = Subscribe;
			// Create the Google API Client
			mClient = new GoogleApiClientBuilder(this)
				.AddApi(FitnessClass.RECORDING_API)
				.AddScope(new Scope(Scopes.FitnessActivityRead))
				.AddConnectionCallbacks(clientConnectionCallback)
				.AddOnConnectionFailedListener((ConnectionResult result) => {
							Log.Info(TAG, "Connection failed. Cause: " + result.ToString());
					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();
		}
        void BuildFitnessClient()
        {
            var clientConnectionCallback = new ClientConnectionCallback();

            clientConnectionCallback.OnConnectedImpl = () => FindFitnessDataSources();
            mClient = new GoogleApiClient.Builder(this)
                      .AddApi(FitnessClass.SENSORS_API)
                      .AddScope(new Scope(Scopes.FitnessLocationRead))
                      .AddConnectionCallbacks(clientConnectionCallback)
                      .AddOnConnectionFailedListener((ConnectionResult result) => {
                Log.Info(TAG, "Connection failed. Cause: " + result);
                if (!result.HasResolution)
                {
                    // Show the localized error dialog
                    GooglePlayServicesUtil.GetErrorDialog(result.ErrorCode, this, 0).Show();
                    return;
                }
                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();
        }
        async void BuildFitnessClient(Activity activity)
        {
            var clientConnectionCallback = new ClientConnectionCallback();

            clientConnectionCallback.OnConnectedImpl = () => {
                /*DataSet dataSet = InsertFitnessData ();
                 *
                 * Log.Info (TAG, "Inserting the dataset in the History API");
                 * var insertStatus = (Statuses)FitnessClass.HistoryApi.InsertData (mClient, dataSet).Await (1, TimeUnit.Minutes);
                 *
                 * if (!insertStatus.IsSuccess) {
                 *      Log.Info (TAG, "There was a problem inserting the dataset.");
                 *      return;
                 * }
                 *
                 * Log.Info (TAG, "Data insert was successful!");
                 *
                 * DataReadRequest readRequest = QueryFitnessData ();
                 *
                 * var dataReadResult = await FitnessClass.HistoryApi.ReadDataAsync (mClient, readRequest);
                 *
                 * PrintData (dataReadResult);*/

                RefreshHealthStateData();
            };

            // Create the Google API Client
            mClient = new GoogleApiClient.Builder(activity)
                      .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, activity, 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(activity, REQUEST_OAUTH);
                    } catch (IntentSender.SendIntentException e) {
                        Log.Error(TAG, "Exception while starting resolution activity", e);
                    }
                }
            }).Build();
        }
        async Task BuildFitnessClient()
        {
            var clientConnectionCallback = new ClientConnectionCallback();
            clientConnectionCallback.OnConnectedImpl = async () => {
                DataSet dataSet = InsertFitnessData();

                Log.Info(TAG, "Inserting the dataset in the History API");
                var insertStatus = (Statuses)FitnessClass.HistoryApi.InsertData(mClient, dataSet).Await(1, TimeUnit.Minutes);

                if (!insertStatus.IsSuccess)
                {
                    Log.Info(TAG, "There was a problem inserting the dataset.");
                    return;
                }

                Log.Info(TAG, "Data insert was successful!");

                DataReadRequest readRequest = QueryFitnessData();

                var dataReadResult = await FitnessClass.HistoryApi.ReadDataAsync(mClient, readRequest);

                PrintData(dataReadResult);
            };
            // Create the Google API Client
            mClient = new GoogleApiClient.Builder(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();
        }
예제 #7
0
        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();
        }
예제 #8
0
		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)
				.AddApi (FitnessClass.SESSIONS_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 ();
		}
예제 #9
0
 /// <summary>
 /// Устанавливает callback для обратной связи.
 /// </summary>
 /// <param name="aCallback">Callback.</param>
 public void SetCallback(ClientConnectionCallback aCallback)
 {
     callback = aCallback;
 }