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

你离开我真会死。 提交于 2019-12-19 04:48:13

问题


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 have looked here stackoverflow answer 1 and here stackoverflow answer 2, and have made sure to use test accounts that are part of my inner circles. (family good enough?)

In testing:

I have tried sending the invitation prior to logging in the other user (I Have never gotten the gameHelper onConnected(Bundle hintConnection) to have a non null value).

I have tried sending the invitation after both accounts are logged in. (1 time a notification came through and popped up the view at the top asking to play, that's it) and have waited, and waited, and waited for anything to fire (nothing in the logs ever shows anything happening, and since there is no return value for sending the invite, nothing to see about how the invite is doing)

I can (right after the sender goes into the Waiting Room) go to See Invitations and the invitation is there. I can also use the GamesClient loadInvitations method, and get the invitationBuffer back in that listener. If I log out one of the users, then I (sometimes) get Invitation notifications in the status bar when I invite the other test account(length of time varies from a few minutes, to up to a half hour later), so I know the invitations are being sent out, and most likely intercepted by something as the documentation says

public void registerInvitationListener (OnInvitationReceivedListener listener)

Register a listener to intercept incoming invitations for the currently signed-in user. If a listener is registered by this method, the incoming invitation will not generate a status bar notification as long as this client remains connected.

Note that only one listener may be active at a time. Calling this method while another listener was previously registered will replace the original listener with the new one. Parameters listener the listener that is called when a new invitation is received. The listener is called on the main thread.

So my testing shows the first part is working (hehe, just got a status bar notification of an invite sent 29 minutes ago while typing this...)

I honestly don't know about the second part, as I said, I can't ever get the listener to fire!

So, is there any way to get feedback about the Invitation? If not, are there any other steps necessary to get the listener to fire?


回答1:


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.



来源:https://stackoverflow.com/questions/17248402/oninvitationreceivedlistener-does-not-fire-reliably-if-at-all-google-play-ga

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