I integrated google games services in my game, including Leaderboards and achievements. If the user opens the leaderboard or achievement activity, he has the possibility to sign out from the settings in the right upper corner.
How can I check if the user is actually signed in? getGamesClient.isConnected() is still true, although the user logged out from the google view.
If I'm clicking the logout button (which is still there, becaus gamesClient is still connected) I get an SecurityException:
08-16 11:01:21.262 14288-14288/? E/AndroidRuntime: FATAL EXCEPTION: main java.lang.SecurityException at android.os.Parcel.readException(Parcel.java:1425) at android.os.Parcel.readException(Parcel.java:1379) at com.google.android.gms.internal.bm$a$a.a(Unknown Source) at com.google.android.gms.internal.bj.signOut(Unknown Source) at com.google.android.gms.games.GamesClient.signOut(Unknown Source)
At the moment, I am checking the ActivityForResult response code and disconnecting the GamesClient, if it's in inconsistent state, but I don't like that approach.
I think what you need is: isSignedIn(); Like this:
This is will return a true or false if user is signed or not. The method in GameHelper.java:
Hope it helps.
In my case I am doing as following. On
MainActivity
ovverideonActivityResult()
.RC_UNUSED
is therequestCode
when you call to openLeaderboards
,Achievements
andSettings
activity from Google Play service app.Write your
signOut()
method as followingDon't forget to update your UI on the end of
signOut()
Try handling onActivityResult:
RC_YOUR_UNIQUE_ID is id you've used for showing Leaderboard or Achievements activity.