当玩家轮流使用时,我会在通知栏中收到通知,而不是在游戏运行时在游戏中收听
实施 OnInvitationReceivedListener 和 OnTurnBasedMatchUpdateReceivedListener
在 onConnected(Bundle connectionHint)中,我添加了 Games.Invitations.registerInvitationListener(mGoogleApiClient,this)和 Games.TurnBasedMultiplayer.registerMatchUpdateListener(mGoogleApiClient,此)
覆盖这些方法
@Override
public void onTurnBasedMatchReceived(TurnBasedMatch match) {
Toast.makeText(this, "A match was updated.",Toast.LENGTH_LONG).show();
}
@Override
public void onTurnBasedMatchRemoved(String s) {
Toast.makeText(this, "A match was canceled.",Toast.LENGTH_LONG).show();
finish();
}
@Override
public void onInvitationReceived(Invitation invitation) {
Toast.makeText(this, "An invitation received.",Toast.LENGTH_LONG).show();
}
@Override
public void onInvitationRemoved(String s) {
Toast.makeText(this, "An invitation removed.",Toast.LENGTH_LONG).show();
}
我无法获取代码来收听收到的邀请/通知。
答案 0 :(得分:1)
如果您通过点击通知开始游戏,则匹配将作为' connectionHint'到onConnected()。您可以使用以下代码进行检查:
public void onConnected(Bundle connectionHint) {
Log.d(TAG, "onConnected(): Connection successful");
// Retrieve the TurnBasedMatch from the connectionHint
if (connectionHint != null) {
mTurnBasedMatch = connectionHint.getParcelable(Multiplayer.EXTRA_TURN_BASED_MATCH);
if (mTurnBasedMatch != null) {
if (mGoogleApiClient == null || !mGoogleApiClient.isConnected()) {
Log.d(TAG, "Warning: accessing TurnBasedMatch when not connected");
}
updateMatch(mTurnBasedMatch);
return;
}
}
// handle registering callbacks and updating status here....
}
只有当你想在应用程序运行时在应用程序中处理这些通知时才需要监听器,因此你不需要让播放器通过播放游戏进入通知栏,然后返回你的申请。