internal FitnessOptions GetFitnessOptions(params HealthDataType[] dataTypes) { var fitnessBuilder = FitnessOptions.InvokeBuilder(); foreach (var dataType in dataTypes) { fitnessBuilder.AddDataType(dataType.ToGoogleFit().TypeIdentifier, FitnessOptions.AccessRead); } return(fitnessBuilder.Build()); }
internal FitnessOptions FitnessPermissionOptions(HealthDataType[] writeDataTypes, HealthDataType[] readDataTypes) { var fitnessBuilder = FitnessOptions.InvokeBuilder(); foreach (var dataType in writeDataTypes) { fitnessBuilder.AddDataType(dataType.ToGoogleFit().TypeIdentifier, FitnessOptions.AccessWrite); } foreach (var dataType in readDataTypes) { fitnessBuilder.AddDataType(dataType.ToGoogleFit().TypeIdentifier, FitnessOptions.AccessRead); } return(fitnessBuilder.Build()); }
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); } }