显示活动列表Google Play游戏

时间:2016-05-14 09:14:32

标签: android google-play-games

我在Google Play Developer中创建了一些活动,我想开始一个显示所有活动的活动。有没有办法做到这一点?

对于任务,我这样做:

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

但是我无法找到显示所有事件列表的事件

1 个答案:

答案 0 :(得分:1)

好的事情在Google的Adding Events and Quests to Your Android Game

中有详细记载

以下代码段显示了如何在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