【问题标题】:onInvitationReceived Not Being CalledonInvitationReceived 未被调用
【发布时间】:2013-09-15 20:53:28
【问题描述】:

我的 Activity 正在实现 OnInvitationReceivedListener 以及所有其他游戏服务项目。它要求我实现了 onInvitationReceived 函数(即,如果我不这样做,则会给出错误),这很好。问题是,我可以向我的帐户发送邀请,但它不会调用 onInvitationReceived 函数。其他听众工作,我可以通过打开邀请列表并接受它来开始游戏等等,但这个函数根本不会被调用。它也应该使用该事件,但我仍然会收到外部通知。

我错过了什么吗?是不是像下面这样简单?所有其他侦听器都在工作...

public class MyActivity extends BaseGameActivity
    implements View.OnClickListener, RealTimeMessageReceivedListener,
    RoomStatusUpdateListener, RoomUpdateListener, OnInvitationReceivedListener
{
    public MyActivity(){...}
    ...

    public void onInvitationReceived(Invitation arg0) 
    {
        Log.v("meh", "Invitation Received");
    }
}

【问题讨论】:

    标签: java android listeners google-play-games


    【解决方案1】:

    您是否注册MyActivity 进行回调?

    由于您使用的是BaseGameActivity,请尝试将其放入您的连接后回调中:

    getGamesClient().registerInvitationListener(this);
    

    我有点惊讶这不是为你完成的,但是在查看 BaseGameActivity 类时我看不到它。

    【讨论】:

    • 哇。是的,我很惊讶这也不是自动的。那成功了。谢谢!
    【解决方案2】:

    我遇到了类似的问题。 (每次启动服务时,我仍然没有破解邀请捆绑包上的代码不为空......即使有邀请等待......)

    从这里Previous StackOverflow issue for Invitaion Listener 我确实得到了大部分解决的问题。 (因为我确实在我的应用程序代码中收到了新邀请的通知)但是,如果邀请已被撤销,没有什么可以告诉你......

    所以,我还运行了一个计时器并在我的代码中执行此操作:

    @Override
        public void loadInvitations(){
            mHelper.getGamesClient().loadInvitations(new OnInvitationsLoadedListener() {
    
                @Override
                public void onInvitationsLoaded(int statusCode, InvitationBuffer buffer) {
                    dLog("invitations loaded " + buffer.getCount());
                    if(mHelper.getGamesClient().STATUS_OK == statusCode  && buffer.getCount() > 0){
                        if(mGHInterface != null){
                            mGHInterface.haveInvitations(buffer.getCount());
                        } 
                    } else if (mGHInterface != null){
                        mGHInterface.haveInvitations(0);
                    }
    
                }
            });
        }
    

    这取决于您希望多久运行一次,但通过这种方式,我发现至少我确实知道邀请是否存在,并相应地更新我的应用程序的操作。

    【讨论】:

    • Jeremy,你有没有让 Bundle 不为空?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-07
    • 2016-05-21
    • 2012-02-15
    • 2011-11-17
    • 2019-10-22
    • 2016-04-03
    相关资源
    最近更新 更多