如何将获得的xp和成就添加到谷歌游戏个人资料?

时间:2016-06-01 14:00:30

标签: android google-play google-play-services google-play-games achievements

我已经制作了一个游戏应用程序,并在谷歌商店发布,我已经将谷歌成就xp添加到我的应用程序,但我没有找到互联网上的指南我应该在谷歌游戏配置文件中添加玩家获得的xp而且它(谷歌游戏应用程序)没有显示成就和xp它只显示排行榜。

这是我的代码: -

void giveAchievements(int counter) {
if (counter == 10) {   
    int xp = getXp();
    xp += 500;
    saveXp(xp);
    if(getApiClient().isConnected()) {
        Games.Achievements.unlock(getApiClient(),   getString(R.string.achievement_first_10_clicks));   
        Games.Leaderboards.submitScoreImmediate(getApiClient(), "CgkI-    eXOwZsFEAIQBg", counter);
    }
}
}

private int getXp() {
SharedPreferences sharedPref =   PreferenceManager.getDefaultSharedPreferences(this);
return sharedPref.getInt("xp", 0);
}

private void saveXp(int xp) {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt("xp", xp);
editor.apply();
}

以下是我的应用image of achievements

中的成就图片

在谷歌播放配置文件中,xp不会添加到配置文件中,此处应用程序的成就部分也未显示: - Game profile that don't contain xp additions and achievements

1 个答案:

答案 0 :(得分:0)

尝试按GPGS Displaying Achievements指南中的说明调用getAchievementsIntent()。这是Google撰写的Android指南。

startActivityForResult(Games.Achievements.getAchievementsIntent(mGoogleApiClient),
REQUEST_ACHIEVEMENTS);

同时尝试检查此SO thread是否有帮助。

Google Play Games Github sample中,它被调用如下:

public void onShowAchievementsRequested() {
        if (isSignedIn()) {
            startActivityForResult(Games.Achievements.getAchievementsIntent(mGoogleApiClient),
                    RC_UNUSED);
        } else {
            BaseGameUtils.makeSimpleDialog(this, getString(R.string.achievements_not_available)).show();
        }
}