In trying out the button clicker demo of the Play Game Services, I have not had any luck (ok, 1 time out of hundreds) of getting the OnInvitationReceivedListener to fire.
I was having the same issue.
I do not use the BaseGameActivity
class.
According to https://developers.google.com/games/services/android/multiplayer#during_gameplay , the proper way to register the listener is in the onConnected()
callback.
I followed the above directions, but onConnected()
was never called, so my InvitationListener
was never registered.
My problem was that I wasn't explicitly requesting the Plus client, and I wasn't registering the proper callback at all. Implementing ConnectionCallbacks
and overriding the OnConnected()
method isn't enough - the GameHelper
doesn't register the callback for you.
public class MainActivity extends AndroidApplication implements
..., ConnectionCallbacks,
OnInvitationReceivedListener {
...
@Override
public void onCreate(Bundle savedInstanceState) {
...
gameHelper = new GameHelper(this);
gameHelper.setup(this, GameHelper.CLIENT_GAMES | GameHelper.CLIENT_PLUS);
gameHelper.getPlusClient().registerConnectionCallbacks(this);
...
}
@Override
public void onConnected(Bundle connectionHint) {
gameHelper.getGamesClient().registerInvitationListener(this);
...
}
After registering the proper two callbacks, I now receive invitation notifications during gameplay.