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

自闭症网瘾萝莉.ら 提交于 2019-12-01 01:42:52

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!