我正在使用firebase auth和实时数据库创建一个笔记应用程序 我坚持使用谷歌认证的设置 这是我的代码:
`package zohar.com.blablabla;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.common.api.GoogleApiClient;
public class LoginActivity extends AppCompatActivity implements
GoogleApiClient.OnConnectionFailedListener, View.OnClickListener {
SignInButton signInButton;
GoogleApiClient mGoogleApiClient;
public static final int RC_SIGN_IN = 9001;
public static final String TAG = "SignInActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
signInButton = (SignInButton) findViewById(R.id.signInButtonGoogle);
signInButton.setOnClickListener(this);
}
@Override
public void onClick(View v) {
signIn();
}
private void signIn() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
@Override
public 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);
}
}
private void handleSignInResult(GoogleSignInResult result) {
Log.d(TAG, "handleSignInResult:" + result.isSuccess());
if (result.isSuccess()) {
//connected successfully
Toast.makeText(this, "You are successfully connected!", Toast.LENGTH_SHORT).show();
Intent toMainActivityIntent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(toMainActivityIntent);
}
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Log.d(TAG, "onConnectionFailed:" + connectionResult);
Toast.makeText(this, "We are currently facing with google/'s api issues,
please try again later", Toast.LENGTH_LONG).show();
}
}`
问题是,每当我点击登录按钮时,它甚至没有显示帐户选择器(我不知道它是否重要,但我的模拟器上有超过1个谷歌帐户)。当我点击它时,屏幕变得很暗,而不是常规 每次HandleSignInResult都返回False。
*我确实注册了我的项目并插入了sha-1 **对不起,如果我犯了一些拼写/语法错误。我还在学英语,这不是我的主要语言 感谢。
编辑:这是警告: 08-14 10:52:34.116 2355-2355/? W/art: Unexpected CPU variant for X86 using
defaults: x86
08-14 10:52:34.404 2355-2355/zohar.com.notescloud W/System: ClassLoader
referenced unknown path: /data/app/zohar.com.notescloud-2/lib/x86
08-14 10:52:34.564 2355-2378/zohar.com.notescloud W/DynamiteModule: Local
module descriptor class for com.google.firebase.auth not found.
08-14 10:52:34.579 2355-2378/zohar.com.notescloud W/DynamiteModule: Local
module descriptor class for com.google.firebase.auth not found.
08-14 10:52:35.009 2355-2355/zohar.com.notescloud W/art: Before Android 4.1,
method android.graphics.PorterDuffColorFilter
android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
08-14 10:52:35.209 2355-2355/zohar.com.notescloud W/System: ClassLoader referenced unknown path:
08-14 10:52:35.405 2355-2355/zohar.com.notescloud W/System: ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/00000006/n/x86
08-14 10:52:35.856 2355-2430/zohar.com.notescloud W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
08-14 10:52:36.030 2355-2355/zohar.com.notescloud W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
c
调试:
08-14 11:02:08.029 2355-11693/zohar.com.notescloud D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=46612, firebase_screen_class(_sc)=LoginActivity, firebase_screen_id(_si)=3256989730768445770}]
08-14 11:02:08.072 2355-11693/zohar.com.notescloud D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=LoginActivity, firebase_previous_id(_pi)=3256989730768445770, firebase_screen_class(_sc)=SignInHubActivity, firebase_screen_id(_si)=3256989730768445773}]
08-14 11:02:08.178 2355-11693/zohar.com.notescloud D/FA: Connected to remote service
08-14 11:02:08.183 2355-2430/zohar.com.notescloud D/EGL_emulation: eglMakeCurrent: 0x9aa2b320: ver 2 0 (tinfo 0x9c741ef0)
08-14 11:02:08.205 2355-2430/zohar.com.notescloud D/EGL_emulation: eglMakeCurrent: 0x9aa2b320: ver 2 0 (tinfo 0x9c741ef0)
08-14 11:02:08.947 2355-2355/zohar.com.notescloud D/SignInActivity: handleSignInResult:false
08-14 11:02:08.953 2355-11693/zohar.com.notescloud D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=SignInHubActivity, firebase_previous_id(_pi)=3256989730768445773, firebase_screen_class(_sc)=LoginActivity, firebase_screen_id(_si)=3256989730768445770}]
EDIT2:固定! 我太愚蠢了,并且自动完成了GOOGLE_SIGN_IN到GOOGLE_GAMES_SIGN_IN。 Sry人。