예제 #1
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);
     }
 }
예제 #2
0
        public override Task <bool> RequestPermissionAsync(params HealthDataType[] dataTypes)
        {
            var fitnessOptions = GetFitnessOptions(dataTypes);

            _tcsAuth = new TaskCompletionSource <bool>();

            if (HasOAuthPermission(fitnessOptions))
            {
                _tcsAuth.SetResult(true);
            }
            else
            {
                GoogleSignIn.RequestPermissions(CurrentActivity, REQUEST_CODE,
                                                GoogleSignIn.GetLastSignedInAccount(_currentContext), fitnessOptions);
            }

            return(_tcsAuth.Task);
        }
예제 #3
0
        public void RequestFitnessPermissions()
        {
            //we have to do all this hullaballoo because Xamarin.PlayServices.Fitness does not contain a constructor for FitnessOptions
            //IntPtr classRef = JNIEnv.FindClass("com/google/android/gms/fitness/FitnessOptions$Builder");
            //IntPtr constructorId = JNIEnv.GetMethodID(classRef, "<init>", "I(V)");
            //IntPtr referenceInstance = JNIEnv.NewObject(classRef, constructorId);

            //var fitnessApiOptions = new FitnessOptions.Builder()
            var fitnessApiOptions = FitnessOptions.InvokeBuilder()
                                    .AddDataType(Android.Gms.Fitness.Data.DataType.AggregateActivitySummary, FitnessOptions.AccessWrite)
                                    .AddDataType(Android.Gms.Fitness.Data.DataType.AggregateSpeedSummary, FitnessOptions.AccessWrite)
                                    .Build();

            account = GoogleSignIn.GetLastSignedInAccount(this);

            if (account == null && !googleLoginInProgress)
            {
                GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn)
                                          .RequestEmail()
                                          .Build();

                var signInClient = GoogleSignIn.GetClient(this, gso);
                googleLoginInProgress = true;
                StartActivityForResult(signInClient.SignInIntent, REQUEST_GOOGLE_SIGN_IN);
                return;
            }

            if (!GoogleSignIn.HasPermissions(account, fitnessApiOptions))
            {
                GoogleSignIn.RequestPermissions(
                    this,
                    REQUEST_FITNESS_PERMISSIONS,
                    account,
                    fitnessApiOptions);
            }
            else
            {
                HasGoogleFitnessPermissions = true;
                GoogleFitnessPermissionsUpdated?.Invoke(HasGoogleFitnessPermissions);
            }
        }