MDodd423
MDodd423

Reputation: 23

How to properly dismiss Google Play Games Account Picker?

When the user presses the sign-in button the Account Picker launches. If they press elsewhere on the screen other than the Account Picker it dismisses and logcat reports:

W/SignInActivity: onSignInFailed()... Sign in failed during 2 ==> Returning non-OK result: 0 W/AutoManageHelper: Unresolved error while connecting client. Stopping auto-manage.

The OnActivityResult() is then called

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    if (requestCode == RC_SIGN_IN) {
        Task<GoogleSignInAccount> task =
                GoogleSignIn.getSignedInAccountFromIntent(intent);

        try {
            GoogleSignInAccount account = task.getResult(ApiException.class);
            onConnected(account);
        } catch (ApiException apiException) {
            String message = apiException.getMessage();
            if (message == null || message.isEmpty()) {
                message = getString(R.string.signin_other_error);
            }

            onDisconnected();

            if(message.startsWith("13")){
                new AlertDialog.Builder(MainActivity.this)
                        .setTitle(R.string.alert_nologin_title)
                        .setMessage(R.string.alert_nologin_message)
                        .setNeutralButton(android.R.string.ok, null)
                        .show();
            }else{
                new AlertDialog.Builder(this)
                        .setMessage(message)
                        .setNeutralButton(android.R.string.ok, null)
                        .show();
            }
        }
    }
}

The AlertDialog.Builder was displaying with a message of 13: when this occurred so I included the if statement to address and target this specific circumstance.

The app is registered in the Google Play Console and can connect under normal circumstance without issue. Also previously this issue would crash the app but that is no longer the case and the user can now dismiss or log in/out as often as they like and the app will remain stable.

The project is hosted on GitHub if any more information is needed: https://github.com/MDodd423/TapAttack

Thanks for any help.

Upvotes: 0

Views: 227

Answers (1)

Teyam
Teyam

Reputation: 8102

Note that before making calls to specific Google services, you may first need to register your app in the Google Developer Console. If you haven't done yet, set up a project and application in the API Console.

Then, check Accessing Google APIs which also discussed starting an automatically managed connection. Your GoogleApiClient instance will automatically connect after your activity calls onStart() and disconnect after calling onStop().

Check this related SO posts for additional insights:

Upvotes: 1

Related Questions