Login with Google (Android Studio)

3

Good evening, I'm not a programmer but I'm very interested in the subject. I've been guiding myself with tutorials on youtube, mainly Google Login on Android . But trying to test the app with a valid gmail account does not allow me to enter the "main activity" and the toast message I used when not logged in appears.

I would appreciate knowing what my error or omission is.

Greetings and thanks!

package app.livup.com.livup;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
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 {

    private GoogleApiClient googleApiClient;

    private SignInButton signInButton;

    public static final int SIGN_IN_CODE = 777;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .build();

        googleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this, this)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .build();

        signInButton = (SignInButton) findViewById(R.id.signInButton);
        signInButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient);
                startActivityForResult(intent, SIGN_IN_CODE);
            }
        });

    }

    @Override
    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == SIGN_IN_CODE) {
            GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
            handleSignInResult(result);
        }
    }

    private void handleSignInResult(GoogleSignInResult result) {
        if (result.isSuccess()) {
            goMainScreen();
        } else {
            Toast.makeText(this, R.string.not_log_in, Toast.LENGTH_SHORT).show();
        }
    }

    private void goMainScreen() {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }
}

LogCat:

>     03-03 02:05:15.439 2525-2525/? I/art: Not late-enabling -Xcheck:jni (already on)
>     03-03 02:05:15.440 2525-2525/? W/art: Unexpected CPU variant for X86 using defaults: x86
>     03-03 02:05:15.545 2525-2525/? W/System: ClassLoader referenced unknown path: /data/app/app.livup.com.livup-1/lib/x86
>     03-03 02:05:15.566 2525-2525/? D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping
> initialization.
>     03-03 02:05:15.577 2525-2525/? D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping
> initialization.
>     03-03 02:05:15.638 2525-2525/? I/FA: App measurement is starting up, version: 10298
>     03-03 02:05:15.638 2525-2525/? I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
>     03-03 02:05:15.662 2525-2525/? I/FA: To enable faster debug mode event logging run:
>                                            adb shell setprop debug.firebase.analytics.app app.livup.com.livup
>     03-03 02:05:15.698 2525-2525/? I/FirebaseInitProvider: FirebaseApp initialization successful
>     03-03 02:05:15.700 2525-2525/? I/InstantRun: Starting Instant Run Server for app.livup.com.livup
>     03-03 02:05:16.021 2525-2525/? 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
>     03-03 02:05:16.037 2525-2525/? V/FA: onActivityCreated
>     03-03 02:05:16.186 2525-2525/? W/System: ClassLoader referenced unknown path: /system/priv-app/PrebuiltGmsCore/lib/x86
>     03-03 02:05:16.196 2525-2525/? W/System: ClassLoader referenced unknown path: 
>     03-03 02:05:16.196 2525-2525/? W/System: ClassLoader referenced unknown path: /system/priv-app/PrebuiltGmsCore/lib/x86
>     03-03 02:05:16.223 2525-2525/? W/System: ClassLoader referenced unknown path:
> /data/user_de/0/com.google.android.gms/app_chimera/m/00000005/n/x86
>     03-03 02:05:16.450 2525-2525/? D/AutoManageHelper: starting AutoManage for client 0 false false
>     03-03 02:05:16.460 2525-2525/app.livup.com.livup D/AutoManageHelper: onStart true
> {0=com.google.android.gms.internal.zzaaa$zza@cb05238}
>     03-03 02:05:16.478 2525-2592/app.livup.com.livup V/FA: Using measurement service
>     03-03 02:05:16.478 2525-2592/app.livup.com.livup V/FA: Connection attempt already in progress
>     03-03 02:05:16.479 2525-2592/app.livup.com.livup V/FA: Activity resumed, time: 14347
>     03-03 02:05:16.538 2525-2592/app.livup.com.livup D/FA: Connected to remote service
>     03-03 02:05:16.539 2525-2592/app.livup.com.livup V/FA: Processing queued up service tasks: 2
>     03-03 02:05:16.671 2525-2658/app.livup.com.livup I/OpenGLRenderer: Initialized EGL, version 1.4
>     03-03 02:05:16.671 2525-2658/app.livup.com.livup D/OpenGLRenderer: Swap behavior 1
>     03-03 02:05:16.742 2525-2525/app.livup.com.livup 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
>     03-03 02:05:16.802 2525-2658/app.livup.com.livup E/EGL_emulation: tid 2658: eglSurfaceAttrib(1178): error 0x3009 (EGL_BAD_MATCH)
>     03-03 02:05:16.802 2525-2658/app.livup.com.livup W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa46ff200,
> error=EGL_BAD_MATCH
>     03-03 02:05:21.579 2525-2592/app.livup.com.livup V/FA: Inactivity, disconnecting from the service
>     03-03 02:05:25.395 2525-2592/app.livup.com.livup V/FA: Recording user engagement, ms: 8916
>     03-03 02:05:25.396 2525-2592/app.livup.com.livup V/FA: Using measurement service
>     03-03 02:05:25.397 2525-2592/app.livup.com.livup V/FA: Connecting to remote service
>     03-03 02:05:25.405 2525-2592/app.livup.com.livup V/FA: Activity paused, time: 23263
>     03-03 02:05:25.412 2525-2592/app.livup.com.livup I/FA: Tag Manager is not found and thus will not be used
>     03-03 02:05:25.414 2525-2525/app.livup.com.livup V/FA: onActivityCreated
>     03-03 02:05:25.414 2525-2592/app.livup.com.livup D/FA: Logging event (FE): _e, Bundle[{_o=auto, _et=8916, _sc=LoginActivity,
> _si=8222527634204196242}]
>     03-03 02:05:25.514 2525-2658/app.livup.com.livup E/EGL_emulation: tid 2658: eglSurfaceAttrib(1178): error 0x3009 (EGL_BAD_MATCH)
>     03-03 02:05:25.514 2525-2658/app.livup.com.livup W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa46ff2a0,
> error=EGL_BAD_MATCH
>     03-03 02:05:25.528 2525-2592/app.livup.com.livup V/FA: Using measurement service
>     03-03 02:05:25.528 2525-2592/app.livup.com.livup V/FA: Connection attempt already in progress
>     03-03 02:05:25.528 2525-2592/app.livup.com.livup V/FA: Using measurement service
>     03-03 02:05:25.528 2525-2592/app.livup.com.livup V/FA: Connection attempt already in progress
>     03-03 02:05:25.529 2525-2592/app.livup.com.livup V/FA: Activity resumed, time: 23304
>     03-03 02:05:25.529 2525-2592/app.livup.com.livup V/FA: Screen exposed for less than 1000 ms. Event not sent. time: 94
>     03-03 02:05:25.529 2525-2592/app.livup.com.livup V/FA: Using measurement service
>     03-03 02:05:25.530 2525-2592/app.livup.com.livup V/FA: Connection attempt already in progress
>     03-03 02:05:25.530 2525-2592/app.livup.com.livup V/FA: Activity paused, time: 23384
>     03-03 02:05:25.585 2525-2592/app.livup.com.livup D/FA: Connected to remote service
>     03-03 02:05:25.586 2525-2592/app.livup.com.livup V/FA: Processing queued up service tasks: 4
>     03-03 02:05:30.440 2525-2592/app.livup.com.livup V/FA: Activity resumed, time: 28307
>     03-03 02:05:30.525 2525-2658/app.livup.com.livup E/EGL_emulation: tid 2658: eglSurfaceAttrib(1178): error 0x3009 (EGL_BAD_MATCH)
>     03-03 02:05:30.525 2525-2658/app.livup.com.livup W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa53a0dc0,
> error=EGL_BAD_MATCH
>     03-03 02:05:35.442 2525-2592/app.livup.com.livup V/FA: Inactivity, disconnecting from the service
    
asked by wannabeSith 03.03.2017 в 01:14
source

1 answer

0

Due to problems in the Google Play Services versions, you can have it display a message in the following method:

@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
    Log.d("MIAPP", connectionResult.getErrorMessage());
}

And so have the exact error of the problem.

    
answered by 03.03.2017 в 01:24