Beispiel #1
0
 private void CheckPermissionsAndRun(FitActionRequestCode fitActionRequestCode)
 {
     if (PermissionApproved())
     {
         FitSignIn(fitActionRequestCode);
     }
     else
     {
         RequestRuntimePermissions(fitActionRequestCode);
     }
 }
Beispiel #2
0
 /// <summary>
 /// Checks that the user is signed in, and if so, executes the specified function. If the user is
 /// not signed in, initiates the sign in flow, specifying the post-sign in function to execute.
 /// </summary>
 /// <param name="requestCode">The request code corresponding to the action to perform after sign in.</param>
 private void FitSignIn(FitActionRequestCode requestCode)
 {
     if (IsOAuthPermissionsApproved)
     {
         PerformActionForRequestCode(requestCode);
     }
     else
     {
         GoogleSignIn.RequestPermissions(
             this,
             (int)requestCode,
             GoogleAccount,
             _fitnessOptions);
     }
 }
Beispiel #3
0
        /// <summary>
        /// Runs the desired method, based on the specified request code. The request code is typically
        /// passed to the Fit sign-in flow, and returned with the success callback. This allows the
        /// caller to specify which method, post-sign-in, should be called.
        /// </summary>
        /// <param name="requestCode">The code corresponding to the action to perform.</param>
        private void PerformActionForRequestCode(FitActionRequestCode requestCode)
        {
            switch (requestCode)
            {
            case FitActionRequestCode.FindDataSources:
#if USESENSORSCLIENT
                FindFitnessDataSources();
#endif

#if USESENSORSCLIENT_ASYNC
                FindFitnessDataSourcesAsync();
#endif

#if USESENSORSAPI
                FindFitnessDataSourcesWithSensorsApi();
#endif
                break;
            }
        }
Beispiel #4
0
        private void RequestRuntimePermissions(FitActionRequestCode requestCode)
        {
            var shouldProvideRationale = ActivityCompat.ShouldShowRequestPermissionRationale(
                this, Manifest.Permission.AccessFineLocation);

            // Provide an additional rationale to the user. This would happen if the user denied the
            // request previously, but didn't check the "Don't ask again" checkbox.
            if (shouldProvideRationale)
            {
                Log.Info(TAG, "Displaying permission rationale to provide additional context.");

                Snackbar.Make(
                    FindViewById(Resource.Id.main_activity_view),
                    Resource.String.permission_rationale,
                    Snackbar.LengthIndefinite)
                .SetAction(Resource.String.ok, (obj) =>
                {
                    // Request permission
                    ActivityCompat.RequestPermissions(
                        this,
                        new string[] { Manifest.Permission.AccessFineLocation },
                        (int)requestCode);
                })
                .Show();
            }
            else
            {
                Log.Info(TAG, "Requesting permission(s)...");

                // Request permission. It's possible this can be auto answered if device policy
                // sets the permission in a given state or the user denied the permission
                // previously and checked "Never ask again".
                ActivityCompat.RequestPermissions(this,
                                                  new string[] { Manifest.Permission.AccessFineLocation },
                                                  (int)requestCode);
            }
        }