我嘗試使用Google登錄。我在兩個月前編寫了這個代碼,它工作的很好,當我回到代碼本週時,它不會連接。我檢查了Google的教程,但沒有任何改變。Google登錄失敗
我改變的唯一的事情是gradle文件中的版本,但我試圖再次改變它們,但它沒有幫助。
我看到「失敗的BINDER TRANSACTION」出現在有大圖像的時候,但我在這裏沒有圖像。
有人能告訴我我錯過了什麼嗎?這是代碼:
GoogleApiClient mGoogleApiClient;
private static final int RC_SIGN_IN = 9001;
private ProgressDialog mProgressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
// Build a GoogleApiClient with access to the Google Sign-In API and the
// options specified by gso.
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Log.d("Login", "onConnectionFailed:" + connectionResult);
}
} /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button);
assert signInButton != null;
signInButton.setSize(SignInButton.SIZE_STANDARD);
signInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.sign_in_button:
signIn();
break;
}
}
});
}
private void handleSignInResult(GoogleSignInResult result) {
Log.d("Login Google", "handleSignInResult:" + result.isSuccess());
if (result.isSuccess()) {
// Signed in successfully, show authenticated UI.
GoogleSignInAccount acct = result.getSignInAccount();
Toast.makeText(this, "User name: " + acct.getDisplayName(), Toast.LENGTH_SHORT).show();
} else {
// Signed out, show unauthenticated UI.
Toast.makeText(this, "Sign Out", Toast.LENGTH_SHORT).show();
}
}
private void signIn() {
Log.v("Login", "SignIn");
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
}
}
項目等級:
dependencies {
classpath 'com.google.gms:google-services:3.0.0'
}
應用gradle這個:
dependencies {
compile 'com.google.android.gms:play-services-auth:9.0.2' // Google Sign-in
compile 'com.google.android.gms:play-services:9.0.2'
apply plugin: 'com.google.gms.google-services' // Google Sign-in
}
這是我在logcat中得到:
07-26 10:41:53.275 V/Login: SignIn
07-26 10:41:53.433 E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 1442828)
07-26 10:41:53.764 D/Login Google: handleSignInResult:false
謝謝,但我試過了,它沒有幫助。 – MorZa