Как настроить кнопку входа Google plus

#android

#Android

Вопрос:

Я много пробовал, но не смог настроить кнопку входа в Google plus. Пожалуйста, помогите мне.

Спасибо

Комментарии:

1. Это нарушение политики, если вы изменили это.

Ответ №1:

Во-первых, на layout.xml добавьте свою кнопку:

 <com.google.android.gms.common.SignInButton
android:id="@ id/sign_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
  

При запуске приложения зарегистрируйтесь на этой кнопке в onclicklistener :

 findViewById(R.id.sign_in_button).setOnClickListener(this);
  

А также используйте этот код, который говорит приложению дождаться нажатия кнопки входа:

     /* Track whether the sign-in button has been clicked so that we know to resolve
 * all issues preventing sign-in without waiting.
 */
private boolean mSignInClicked;

/* Store the connection result from onConnectionFailed callbacks so that we can
 * resolve them when the user clicks sign-in.
 */
private ConnectionResult mConnectionResu<

/* A helper method to resolve the current ConnectionResult error. */
private void resolveSignInError() {
  if (mConnectionResult.hasResolution()) {
    try {
      mIntentInProgress = true;
      startIntentSenderForResult(mConnectionResult.getIntentSender(),
          RC_SIGN_IN, null, 0, 0, 0);
    } catch (SendIntentException e) {
      // The intent was canceled before it was sent.  Return to the default
      // state and attempt to connect to get an updated ConnectionResult.
      mIntentInProgress = false;
      mGoogleApiClient.connect();
    }
  }
}

public void onConnectionFailed(ConnectionResult result) {
  if (!mIntentInProgress) {
    // Store the ConnectionResult so that we can use it later when the user clicks
    // 'sign-in'.
    mConnectionResult = resu<

    if (mSignInClicked) {
      // The user has already clicked 'sign-in' so we attempt to resolve all
      // errors until the user is signed in, or they cancel.
      resolveSignInError();
    }
  }
}
  

И используйте этот код onclick (указывает, является ли это кнопкой входа) :

     public void onClick(View view) {
  if (view.getId() == R.id.sign_in_button
    amp;amp; !mGoogleApiClient.isConnecting()) {
    mSignInClicked = true;
    resolveSignInErrors();
  }
}
  

Используйте этот код, чтобы указать, вошли ли вы уже в систему:

     protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
  if (requestCode == RC_SIGN_IN) {
    if (responseCode != RESULT_OK) {
      mSignInClicked = false;
    }

    mIntentInProgress == false;

    if (!mGoogleApiClient.isConnecting()) {
      mGoogleApiClient.connect();
    }
  }
}
  

И добавьте сообщение при успешном входе в систему:

     @Override
public void onConnected(Bundle connectionHint) {
  mSignInClicked = false;
  Toast.makeText(this, "User is connected!", Toast.LENGTH_LONG).show();
}
  

Кроме того, прочтите это:
https://developers.google.com/ /mobile/android/sign-in