Android API IsConnected returns TRUE after logging out

I am developing a game for Android using Google Play Game Services using Xamarin. I am doing my testing using the Android Genymotion emulator. I ran into a problem that seems to be a bug in the implementation of Google Play or Xamarin.

If I log out of my Google account , calls to IGoogleApiClient.IsConnected () continue to return true (although I have obviously just left). If I try to use this API object, I will get exceptions, for example:

java.lang.SecurityException: not signed when calling API

For example, the following code throws the above exception if it is executed after the statement:

public void StartNewMatch() { if (!mGoogleApiClient.IsConnected) { return; } Intent intent = GamesClass.TurnBasedMultiplayer.GetSelectOpponentsIntent(mGoogleApiClient, 1, 1, true); StartActivityForResult(intent, RC_SELECT_PLAYERS); } 

I exit the inbox of Google Play Games (Match Picker); as shown in the pictures below.

Has anyone come across this before? Am I missing something? Are there any problems?

Note. This only happens if you exit the Google user interface. If I manually log out of the user account with something like mGoogleApiClient.Disconnect() , the problem does not occur; mGoogleApiClient.IsConnected() now returns false (as expected).

enter image description here

enter image description here

enter image description here

+7
android google-play-services google-play-games xamarin monogame
source share
2 answers

To synchronize the login state, you MUST correctly implement onActivityResult.

It should look something like this:

NOTE: this is Java code, I'm not sure how it will look exactly with Xamarin, but I hope you can figure it out :)

 @Override protected void onActivityResult(int requestCode, int responseCode, Intent data) { // check for "inconsistent state" if ( responseCode == GamesActivityResultCodes.RESULT_RECONNECT_REQUIRED && requestCode == <your_request_code_here> ) { // force a disconnect to sync up state, ensuring that mClient reports "not connected" mGoogleApiClient.disconnect(); } } 

NOTE: just make sure that you replace the request code in the code that you used. You may also need to check multiple request codes.

+18
source share

If you use the gameHelper classes from the BaseGameUtils library (easier to use), you can change the code above:

 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); gameHelper.onActivityResult(requestCode, resultCode, data); if (resultCode == GamesActivityResultCodes.RESULT_RECONNECT_REQUIRED){ // force a disconnect to sync up state, ensuring that mClient reports "not connected" gameHelper.getApiClient().disconnect(); } } 
0
source share

All Articles