コード例 #1
0
  @Override
  public void onStart() {
    super.onStart();

    OptionalPendingResult<GoogleSignInResult> opr =
        Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
    if (opr.isDone()) {
      // If the user's cached credentials are valid, the OptionalPendingResult will be "done"
      // and the GoogleSignInResult will be available instantly.
      Log.d(TAG, "Got cached sign-in");
      GoogleSignInResult result = opr.get();
      handleSignInResult(result);
    } else {
      // If the user has not previously signed in on this device or the sign-in has expired,
      // this asynchronous branch will attempt to sign in the user silently.  Cross-device
      // single sign-on will occur in this branch.
      showProgressDialog();
      opr.setResultCallback(
          new ResultCallback<GoogleSignInResult>() {
            @Override
            public void onResult(GoogleSignInResult googleSignInResult) {
              hideProgressDialog();
              handleSignInResult(googleSignInResult);
            }
          });
    }
  }
コード例 #2
0
 @Override
 public void onResume() {
   super.onResume();
   OptionalPendingResult<GoogleSignInResult> opr =
       Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
   if (opr.isDone()) {
     GoogleSignInResult result = opr.get();
     handleSignInResult(result);
     showShortenBox(true);
     showSignInButton(false);
   } else {
     opr.setResultCallback(
         new ResultCallback<GoogleSignInResult>() {
           @Override
           public void onResult(GoogleSignInResult googleSignInResult) {
             showSignInButton(true);
             showShortenBox(false);
           }
         });
   }
 }