0

I used google tutorial https://developers.google.com/identity/sign-in/android/start-integrating. But when I click sign-in button app crashes with message:

com.google.android.gms.common.api.ApiException: 8:

I searched for this error and find: https://developers.google.com/android/reference/com/google/android/gms/common/api/CommonStatusCodes.html#INTERNAL_ERROR, but as you see there is no explanation why this error occurs.

Here is Java code:

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

private static final int RC_SIGN_IN = 9001;
private GoogleSignInClient mGoogleSignInClient;
private SignInButton signInButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .build();
    mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
    signInButton = findViewById(R.id.sign_in_button);
    signInButton.setOnClickListener(this);
}

@Override
public void onClick(View v) {
    switch (v.getId()){
        case R.id.sign_in_button:
            signIn();
            break;
    }
}

private void signIn() {
    Intent signInIntent = mGoogleSignInClient.getSignInIntent();
    signInIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    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 GoogleSignInClient.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        // The Task returned from this call is always completed, no need to attach
        // a listener.
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        //handleSignInResult(task);
        try {
            GoogleSignInAccount account = task.getResult(ApiException.class);
            Log.i("User",account.toString());
            Log.i("Mail",account.getEmail());
            Log.i("Name",account.getDisplayName());
        } catch (ApiException e) {
            e.printStackTrace();
            Log.i("Error",e.getMessage());
        }
    }
    else {
        Log.i("User","invalid");
    }
}

Here is layout of the activity above:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.gms.common.SignInButton
    android:id="@+id/sign_in_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</LinearLayout>
Tugberk
  • 41
  • 1
  • 7
  • Check this out https://stackoverflow.com/a/47448899/5518027 – Arpan Sarkar Apr 17 '18 at 07:59
  • I have already done it. – Tugberk Apr 17 '18 at 08:00
  • There are different reasons for "ApiException: 8". For me it happens while downloading files "java.util.concurrent.ExecutionException" from Google Drive. For me, I believe Google Services is causing it as may happen only once in about 900 times and Google Services crashes even though files continue to download. Maybe someone will find this comment helpful, but ApiException: 8 is totally lame. – CmosBattery Jun 10 '18 at 12:10

0 Answers0