OnInvitationReceivedListener does not fire reliably (if at all) - Google Play Game Services Button Clicker

前端 未结 1 1957
無奈伤痛
無奈伤痛 2021-01-07 12:17

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.

相关标签:
1条回答
  • 2021-01-07 12:33

    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.

    0 讨论(0)
提交回复
热议问题