Forum Xamarin.Android

about google sign in

guys i have code for sin in with google when i debug it at the emelatour it works fine even when i connect my phone as emelatour works fine
but my question is when i publish my apk to test it sign in just pop up the menu of google accounts then no thing happened
is it normal because the application didn't uploaded yet to playstore or what is the problem?

Best Answer

  • emadyounanemadyounan ✭✭
    Accepted Answer

    well guys I found the answer I was in need to make it release key store not debug

Answers

  • emadyounanemadyounan Member ✭✭
    edited March 30

    this is my code

                    gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn)
                        .RequestIdToken("Token.apps.googleusercontent.com")
                        .RequestEmail()
                        .Build();
    
                    googleApiClient = new GoogleApiClient.Builder(this)
                    .EnableAutoManage(this, this)
                    .AddApi(Auth.GOOGLE_SIGN_IN_API, gso).Build();
    
      protected override void OnStart()
            {
                base.OnStart();
                var opr = Auth.GoogleSignInApi.SilentSignIn(googleApiClient);
    
                if (opr.IsDone)
                {
                    // If the user's cached credentials are valid, the OptionalPendingResult will be "done"
                    // and the GoogleSignInResult will be available instantly.
                    var result = opr.Get() as GoogleSignInResult;
                    HandleSignInResult(result);
                }
    
            }
            protected override void OnResume()
            {
                base.OnResume();
            }
            public void HandleSignInResult(GoogleSignInResult result)
            {
                if (result.IsSuccess)
                {
                    // Signed in successfully, show authenticated UI.
                    var acct = result.SignInAccount;
                }
                else
                {
                    // Signed out, show unauthenticated UI.
                }
            }
            protected override void OnStop()
            {
                base.OnStop();
    
                if (googleApiClient.IsConnected)
                {
                    googleApiClient.Disconnect();
                }
            }
    
            public void OnConnected(Bundle connectionHint)
            {
                //throw new NotImplementedException();
            }
    
            protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
            {
    
                try
                {
                    base.OnActivityResult(requestCode, resultCode, data);
    
                    if (requestCode == sign_id)
                    {
                        var result = Auth.GoogleSignInApi.GetSignInResultFromIntent(data);
                        HandlessSignIn(result);
                    }
                }
                catch (Exception ex)
                {
                    Toast.MakeText(this, ex.Message.ToString(), ToastLength.Long).Show();
                }
    
                //base.OnActivityResult(requestCode, resultCode, data);
    
            }
    
            private void HandlessSignIn(GoogleSignInResult result)
            {
                try
                {
    
                    if (result.IsSuccess)
                    {
                        var accountDetails = result.SignInAccount;
    
    
    
                            prg.Visibility = ViewStates.Invisible;
    
    
                        }
                    }
                }
                catch (Exception ex)
                {
                    Toast.MakeText(this, ex.Message.ToString(), ToastLength.Long).Show();
                }
    
            }
    
            private void Siggoogle_Click(object sender, EventArgs e)
            {
                prg.Visibility = ViewStates.Visible;
    
                var intent = Auth.GoogleSignInApi.GetSignInIntent(googleApiClient);
                StartActivityForResult(intent, sign_id);
            }
    
  • emadyounanemadyounan Member ✭✭
    Accepted Answer

    well guys I found the answer I was in need to make it release key store not debug

Sign In or Register to comment.