0

I want a Google Login on my Android App.

This is my login method:

private void loginWithGoogle() {
    GoogleSignInOptions signInOptions =
            new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestEmail()
                    .build();
    GoogleSignInClient client = GoogleSignIn.getClient(this, signInOptions);
    startActivityForResult(client.getSignInIntent(), Key.GOOGLE_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 == Key.GOOGLE_SIGN_IN) {
        GoogleSignIn.getSignedInAccountFromIntent(data)
                .addOnSuccessListener(new OnSuccessListener<GoogleSignInAccount>() {
                    @Override
                    public void onSuccess(GoogleSignInAccount googleSignInAccount) {
                        Log.d("werte", "Login successful");
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        Toast.makeText(MainActivity.this, R.string.loginFailed, Toast.LENGTH_SHORT).show();
                        e.printStackTrace();
                    }
                });
    }
}

Google Login in the Firebase console is enabled, the SHA1 Key for debug and live is set and the google-services.json is in the app folder of the project directory.

I don't know what is missing.

Edit: I solved it by linking Google Play with Firebase.

  1. Sign in to Firebase.
  2. Click the Settings icon, then select Project settings.
  3. Click the Integrations tab.
  4. On the Google Play card, click Link.

0 Answers0