Tôi mới phát triển Android và hy vọng sẽ nhận được một số lời khuyên cho vấn đề mà tôi đang gặp phải.Nút đăng nhập Google+ không thể hủy
Ứng dụng của tôi yêu cầu tôi triển khai nút đăng nhập google +.
tiến bộ của tôi
- Tôi làm theo các hướng dẫn và hoàn tất các bước thiết lập cần thiết cho một google + đăng nhập nút
- tôi có thể sử dụng đăng nhập nút và lấy email hồ sơ
Vấn đề của tôi
- Khi google + đăng nhập nút được nhấp, "chọn tài khoản" show thoại, cho phép người dùng chọn từ nhiều gmail có thể chiếm
- Khi người dùng nhấp vào một tài khoản và sau đó nhấp vào nút xác nhận, mọi thứ hoạt động tốt
- Nhưng, khi người dùng nhấp vào nút hủy trong hộp thoại, hộp thoại biến mất và xuất hiện trở lại. Ngay cả khi bạn nhấp vào nút quay lại, hộp thoại sẽ biến mất và xuất hiện trở lại.
Điều này ngăn người dùng chọn các tùy chọn đăng nhập khác.
tôi tự hỏi những gì là sai với mã của tôi, bất kỳ trợ giúp sẽ được đánh giá cao. Cảm ơn.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// facebook sign in
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_sign_in);
facebookLoginSetup(findViewById(android.R.id.content).getRootView());
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.addScope(Plus.SCOPE_PLUS_PROFILE)
.build();
SignInButton sign_in_button = (SignInButton) findViewById(R.id.sign_in_button);
setGooglePlusButtonText(sign_in_button, getString(R.string.google_login_button_label));
findViewById(R.id.sign_in_button).setOnClickListener(this);
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setMessage(getString(R.string.global_message_loading));
mProgressDialog.setCancelable(false);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(mProgressDialog.isShowing()){
mProgressDialog.dismiss();
}
// google
if (requestCode == RC_SIGN_IN) {
if (resultCode != RESULT_OK) {
mSignInClicked = false;
}
mIntentInProgress = false;
if (!mGoogleApiClient.isConnecting()) {
mGoogleApiClient.reconnect();
}
} else {
// facebook
// call registered call back method
callbackManager.onActivityResult(requestCode, resultCode, data);
}
}
@Override
public void onConnectionSuspended(int cause)
{
mGoogleApiClient.connect();
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.sign_in_button && !mGoogleApiClient.isConnecting()) {
if(!mProgressDialog.isShowing()){
mProgressDialog.show();
}
mSignInClicked = true;
mGoogleApiClient.connect();
}
}
@Override
public void onConnected(Bundle connectionHint) {
mSignInClicked = false;
if(mProgressDialog.isShowing()){
mProgressDialog.dismiss();
}
if (Plus.AccountApi.getAccountName(mGoogleApiClient) != null) {
String userEmail = Plus.AccountApi.getAccountName(mGoogleApiClient);
createUser(userEmail);
}
}
@Override
public void onConnectionFailed(ConnectionResult result) {
if (!mIntentInProgress && result.hasResolution()) {
try {
Log.d(MainActivity.TAG, "onConnectionFailed keep retrying");
mIntentInProgress = true;
startIntentSenderForResult(result.getResolution().getIntentSender(),
RC_SIGN_IN, null, 0, 0, 0);
} catch (IntentSender.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;
}
}
}
// google custom button
protected void setGooglePlusButtonText(SignInButton signInButton, String buttonText) {
for (int i = 0; i < signInButton.getChildCount(); i++) {
View v = signInButton.getChildAt(i);
if (v instanceof TextView) {
TextView tv = (TextView) v;
tv.setTextSize(15);
tv.setTypeface(null, Typeface.NORMAL);
tv.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
tv.setText(buttonText);
return;
}
}
}
Điều gì xảy ra nếu bạn nhận xét toàn bộ nội dung của onConnectionĐược yêu cầu? Có thể việc hủy đăng nhập được tính là lỗi kết nối và hiện tại phản hồi từ ứng dụng của bạn đến đó là thử lại. – Finnboy11