ptgamr / cordova-google-play-game

Cordova Plugin For Google Play Game Service
35 stars 64 forks source link

isSignedIn() always returns true after user is signedOut via default dialog #2

Open magabriel opened 9 years ago

magabriel commented 9 years ago

Hi, everyone.

I implemented this plugin in my app and reached the following scenario:

It seems that the return of isSignedIn() does not correctly reflect the real status.

After that, subsequent calls to googleplaygame.showAllLeaderboards() break the app with the exception java.lang.SecurityException: Not signed in when calling API instead of just calling the error callback provided.

Thanks,

paneyi commented 9 years ago

@magabriel, I was facing this exact problem and solved it by modifying the method onActivityResult on GooglePlayGame.java. This way, if the activity exiting is the one we started with the ID ACTIVITY_CODE_SHOW_LEADERBOARD (the leaderboard) and the result is that a reconnection is required (due to an inconsistent state on the api client), we force a disconnect. This can be extended to take into account the achievements view, by adding an OR with the constant ACTIVITY_CODE_SHOW_ACHIEVEMENTS.

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {

        if (requestCode == ACTIVITY_CODE_SHOW_LEADERBOARD
                && resultCode == GamesActivityResultCodes.RESULT_RECONNECT_REQUIRED) {
            Log.d(LOGTAG, "Disconnection from Play Services called from activity with code: " + requestCode);
            gameHelper.disconnect();
        } else {
            gameHelper.onActivityResult(requestCode, resultCode, intent);
        }
    }

What do you think @ptgamr ?