【问题标题】:Show Events list Google Play Games显示活动列表 Google Play 游戏
【发布时间】:2016-05-15 22:19:55
【问题描述】:

我在 Google Play Developer 中创建了一些事件,并且我想启动一个显示所有事件的 Activity。有什么办法吗?

对于任务我这样做:

public void showQuests() {
    Intent questsIntent = Games.Quests.getQuestsIntent(mGoogleApiClient,
        Quests.SELECT_ALL_QUESTS);
    startActivityForResult(questsIntent, 0);
}

但我找不到显示所有事件列表的事件意图

【问题讨论】:

    标签: android google-play-games


    【解决方案1】:

    这在 Google 的 Adding Events and Quests to Your Android Game 中有很好的记录

    以下 sn-p 显示了如何查询 Google Play 游戏服务以获取游戏的所有事件列表:

    // EventCallback is a subclass of ResultCallback; use this to handle the
    // query results
    
    EventCallback ec = new EventCallback();
    
    // Load all events tracked for your game
    com.google.android.gms.common.api.PendingResult<Events.LoadEventsResult>
            pr = Games.Events.load(mGoogleApiClient, true);
    pr.setResultCallback(ec);
    

    如果调用成功,系统会在您的应用中触发 ResultCallback 对象。您应该在 onResult() 方法中处理查询结果:

    class EventCallback implements ResultCallback {
        // Handle the results from the events load call
        public void onResult(com.google.android.gms.common.api.Result result) {
            Events.LoadEventsResult r = (Events.LoadEventsResult)result;
            com.google.android.gms.games.event.EventBuffer eb = r.getEvents();
    
            for (int i=0; i < eb.getCount(); i++) {
                // do something with the events retrieved
            }
            eb.close();
        }
    }
    

    完整的样本在这个repo

    【讨论】:

      猜你喜欢
      • 2016-07-14
      • 1970-01-01
      • 1970-01-01
      • 2013-05-19
      • 2013-07-11
      • 2014-05-30
      • 2014-01-11
      • 2015-01-30
      • 2014-10-19
      相关资源
      最近更新 更多