[英]I can not get my Google sign-in to work via Firebase. The Google button is just unresponsive
The Google button just does nothing, I got no error or nothing. Google按钮什么也不做,我没有错误或什么也没有。 I need another eye to look at it.
我需要另一只眼睛看它。
public class GoogleSignIn extends AppCompatActivity {
private SignInButton googleSignInBtn;
final String TAG ="Google-SignInActivity";
private static final int RC_SIGN_IN = 10;
private GoogleApiClient mGoogleApiClient;
private FirebaseAuth mAuth;
GoogleSignInClient mGoogleSignInClient;
private FirebaseAuth.AuthStateListener mAuthStateListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*mAuthStateListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
if(firebaseAuth.getCurrentUser() != null){
Intent optionIntent = new Intent(GoogleSignIn.this, OptionActivity.class);
startActivity(optionIntent);
}
}
};*/
mAuth = FirebaseAuth.getInstance();
googleSignInBtn = (SignInButton) findViewById(R.id.googleSignIn);
// Configure Google Sign In
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
//mGoogleSignInClient = Auth.GoogleSignInApi.getClient(this, gso);
mGoogleApiClient = new GoogleApiClient.Builder(getApplication())
.enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Toast.makeText(GoogleSignIn.this, "Google sign in Error", Toast.LENGTH_SHORT).show();
}
})
.addApi(Auth.GOOGLE_SIGN_IN_API,gso)
.build();
googleSignInBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
signIn();
}
});
}
@Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthStateListener);
}
private void signIn() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
//Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if(result.isSuccess()) {
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = result.getSignInAccount();
firebaseAuthWithGoogle(account);
} else {
// Google Sign In failed, update UI appropriately
Log.w(TAG, "Google sign in failed");
// ...
}
}
}
private void firebaseAuthWithGoogle(GoogleSignInAccount account) {
Log.d(TAG, "firebaseAuthWithGoogle:" + account.getId());
AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "signInWithCredential:success");
FirebaseUser user = mAuth.getCurrentUser();
Intent optionIntent = new Intent(GoogleSignIn.this, OptionActivity.class);
startActivity(optionIntent);
finish();
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "signInWithCredential:failure", task.getException());
Snackbar.make(findViewById(R.id.googleSignIn), "Authentication Failed.", Snackbar.LENGTH_SHORT).show();
//updateUI(null);
}
// ...
}
});
}
}
My dependencies are below and i have used all sorts of dependencies, but nothing. 我的依赖项在下面,我使用了各种各样的依赖项,但是什么也没有。 I have used all version of firebase depencies
我已经使用了所有版本的Firebase依赖
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.onyebuchboss.bossweatherbitcoinapp"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.google.firebase:firebase-database:15.0.0'
compile 'com.google.firebase:firebase-core:15.0.0'
compile 'com.google.firebase:firebase-auth:15.0.0'
compile 'com.google.android.gms:play-services-auth:15.0.0'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.android.support:design:26.1.0'
}
apply plugin: 'com.google.gms.google-services'
Please find the source code for the XML below 请在下面找到XML的源代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/green"
tools:context=".MainActivity"
tools:ignore="ExtraText">
<com.google.android.gms.common.SignInButton
android:layout_width="351dp"
android:layout_height="wrap_content"
android:layout_above="@+id/login_email"
android:layout_alignEnd="@+id/login_email"
android:layout_alignRight="@+id/login_email"
android:layout_marginBottom="43dp"
android:id="@+id/googleSignIn">
</com.google.android.gms.common.SignInButton>
<AutoCompleteTextView
android:id="@+id/login_email"
android:layout_width="354dp"
android:layout_height="wrap_content"
android:layout_above="@+id/login_password"
android:layout_alignLeft="@+id/login_password"
android:layout_alignStart="@+id/login_password"
android:layout_marginBottom="19dp"
android:hint="@string/prompt_email"
android:textColor="@android:color/white"
tools:textColor="@android:color/white"
tools:textColorHighlight="@android:color/white"/><![CDATA[
tools:layout_editor_absoluteX="17dp"
tools:textColor="@android:color/white"/>
]]>
<EditText
android:id="@+id/login_password"
android:layout_width="351dp"
android:layout_height="wrap_content"
android:layout_above="@+id/login_sign_in_button"
android:layout_centerHorizontal="true"
android:layout_marginBottom="79dp"
android:ems="10"
android:hint="@string/prompt_password"
android:inputType="textPassword"
android:textColorHint="@android:color/white"/>
<Button
android:id="@+id/login_sign_in_button"
android:layout_width="351dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/login_password"
android:layout_alignParentBottom="true"
android:layout_alignStart="@+id/login_password"
android:layout_marginBottom="83dp"
android:text="@string/action_sign_in_short"
tools:background="?attr/colorPrimary"
tools:layout_editor_absoluteY="400dp"
tools:textColor="@android:color/white"/>
<Button
android:id="@+id/login_register_button"
android:layout_width="351dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/login_sign_in_button"
android:layout_alignParentBottom="true"
android:layout_alignStart="@+id/login_sign_in_button"
android:layout_marginBottom="15dp"
android:text="@string/action_register"
android:textColor="@android:color/white"
android:textStyle="bold"
tools:background="@color/colorPrimary"/>
</RelativeLayout>
please add some extra Log messages to these places: your signIn() method, the body of if(result.isSuccess()) {} inside onActivityResult () method. 请在以下位置添加一些额外的Log消息:您的signIn()方法,onActivityResult()方法中if(result.isSuccess()){}的主体。
Then run your app and check if these Log methods have been called. 然后运行您的应用程序,并检查是否已调用这些Log方法。 If not called, the sign-in request was unsuccessful and vice versa.From here, we will figure out what the problem is and move on to the next step.
如果未调用,则登录请求将失败,反之亦然。从这里,我们将找出问题所在,然后继续下一步。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.