protected internal override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);

            mGoogleApiClient = (new GoogleApiClient.Builder(this)).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN).build();

            mGoogleLoginClicked = true;
            if (!mGoogleApiClient.Connecting)
            {
                if (mGoogleConnectionResult != null)
                {
                    resolveSignInError();
                }
                else if (mGoogleApiClient.Connected)
                {
                    GoogleOAuthTokenAndLogin;
                }
                else
                {
                    /* connect API now */
                    Log.d(TAG, "Trying to connect to Google API");
                    mGoogleApiClient.connect();
                }
            }
        }
Пример #2
0
        protected internal override void onStart()
        {
            base.onStart();
            Intent intent  = Intent;
            bool   signout = intent.getBooleanExtra("SIGNOUT", false);

            if (signout)
            {
                signOut();
            }
            else if (!mGoogleIntentInProgress)
            {
                // auto sign in
                mGoogleApiClient.connect();
            }
        }
 /* A helper method to resolve the current ConnectionResult error. */
 private void resolveSignInError()
 {
     if (mGoogleConnectionResult.hasResolution())
     {
         try
         {
             mGoogleIntentInProgress = true;
             mGoogleConnectionResult.startResolutionForResult(this, MainActivity.RC_GOOGLE_LOGIN);
         }
         catch (IntentSender.SendIntentException)
         {
             // The intent was canceled before it was sent.  Return to the default
             // state and attempt to connect to get an updated ConnectionResult.
             mGoogleIntentInProgress = false;
             mGoogleApiClient.connect();
         }
     }
 }