好東西,這是在谷歌的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。