Пример #1
0
        public void RequestPermissions(string[] scopes, Action <SignInStatus> callback)
        {
            using (var bridgeClass = new AndroidJavaClass(HelperFragmentClass))
                using (var currentActivity = AndroidHelperFragment.GetActivity())
                    using (var task =
                               bridgeClass.CallStatic <AndroidJavaObject>("showRequestPermissionsUi", currentActivity,
                                                                          oauthScopes.Union(scopes).ToArray()))
                    {
                        AndroidTaskUtils.AddOnSuccessListener <AndroidJavaObject>(task, /* disposeResult= */ false,
                                                                                  accountWithNewScopes =>
                        {
                            if (accountWithNewScopes == null)
                            {
                                callback(SignInStatus.InternalError);
                                return;
                            }

                            account     = accountWithNewScopes;
                            email       = account.Call <string>("getEmail");
                            idToken     = account.Call <string>("getIdToken");
                            authCode    = account.Call <string>("getServerAuthCode");
                            oauthScopes = oauthScopes.Union(scopes).ToList();
                            callback(SignInStatus.Success);
                        });

                        AndroidTaskUtils.AddOnFailureListener(task, e =>
                        {
                            var failCode = SignInHelper.ToSignInStatus(e.Call <int>("getStatusCode"));
                            OurUtils.Logger.e("Exception requesting new permissions: " + failCode);
                            callback(failCode);
                        });
                    }
        }