Google Api Client interface methods explanation?

夙愿已清 提交于 2020-01-06 18:33:50

问题


    @Override
public void getLeaderboardGPGS() {
    if (gameHelper.isSignedIn()) {
        startActivityForResult(Games.Leaderboards.getLeaderboardIntent(gameHelper.getApiClient(), getString(R.string.event_score)), 100);
    }
    else if (!gameHelper.isConnecting()) {
        loginGPGS();
    }
}

@Override
public void getAchievementsGPGS() {
    if (gameHelper.isSignedIn()) {
        startActivityForResult(Games.Achievements.getAchievementsIntent(gameHelper.getApiClient()), 101);
    }
    else if (!gameHelper.isConnecting()) {
        loginGPGS();
    }
}

Hi folks, can anyone explain to me what these methods do? I have them as part of implementing a GoogleApi interface I made in the context of a tutorial. I especially don't understand the 100 / 101 parts, but the whole thing, in general, is quite confusing for me.

PS. I am making a game in LibGDX and this is my first time touching the Google Play API (or I think any API for that matter)


回答1:


First Method getLeaderboardGPGS show you Leaderboard above your Activity if you are already Signed in otherwise it start signing process.

Above method definition is from Libgdx wiki but it should be

private final static int REQUEST_CODE_UNUSED = 9002;

startActivityForResult(Games.Leaderboards.getLeaderboardIntent(gameHelper.getApiClient(), getString(R.string.leaderboardId)), REQUEST_CODE_UNUSED);

REQUEST_CODE_UNUSED is an arbitrary integer for the request code getString(R.string.leaderboardId) is LEADERBOARD_ID

taken from Google wiki

Second Method getAchievementsGPGS is used to show a player's achievements, call getAchievementsIntent() to get an Intent to create the default achievements UI.

startActivityForResult(Games.Achievements.getAchievementsIntent(gameHelper.getApiClient()), REQUEST_ACHIEVEMENTS);

where REQUEST_ACHIEVEMENTS is an arbitrary integer used as the request code.



来源:https://stackoverflow.com/questions/42147557/google-api-client-interface-methods-explanation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!