将XP添加到Android游戏应用程序

将XP添加到Android游戏应用程序,android,android-studio,google-play-services,achievements,Android,Android Studio,Google Play Services,Achievements,我已经制作了一个游戏应用程序,现在我想将谷歌成就xp添加到我的应用程序中。我应该如何做?我已经使用这个添加了成就 但我在互联网上找不到应该增加玩家已获得的xp的指南 这是我解锁成就但不是解锁xp的代码: void giveAchievements(int counter) { if (counter == 10) { if (getApiClient().isConnected()) { Games.Achievements.unlock(getA

我已经制作了一个游戏应用程序,现在我想将谷歌成就xp添加到我的应用程序中。我应该如何做?我已经使用这个添加了成就 但我在互联网上找不到应该增加玩家已获得的xp的指南

这是我解锁成就但不是解锁xp的代码:

void giveAchievements(int counter) {
    if (counter == 10) {
        if (getApiClient().isConnected()) {
            Games.Achievements.unlock(getApiClient(),
                    getString(R.string.achievement_first_10_clicks));
            Games.Leaderboards.submitScoreImmediate(getApiClient(), "CgkI-  eXOwZsFEAIQBg", counter);
        }
    }
    if (counter == 50) {
        if (getApiClient().isConnected()) {
            Games.Achievements.unlock(getApiClient(),
                    getString(R.string.achievement_50_clicks));
            Games.Leaderboards.submitScoreImmediate(getApiClient(), "CgkI-eXOwZsFEAIQBg", counter);
        }
    }
    if (counter == 100) {
        if (getApiClient().isConnected()) {
            Games.Achievements.unlock(getApiClient(),
                    getString(R.string.achievement_100_clicks));
            Games.Leaderboards.submitScoreImmediate(getApiClient(), getString(R.string.leaderboard_leaderboard), counter);
        }
    }
    if (counter == 250) {
        if (getApiClient().isConnected()) {
            Games.Achievements.unlock(getApiClient(),
                    getString(R.string.achievement_250_clicks));
            Games.Leaderboards.submitScoreImmediate(getApiClient(), "CgkI-eXOwZsFEAIQBg", counter);
        }
    }
    if (counter == 500) {
        if (getApiClient().isConnected()) {
            Games.Achievements.unlock(getApiClient(),
                    getString(R.string.achievement_500_clicks));
            Games.Leaderboards.submitScoreImmediate(getApiClient(), getString(R.string.leaderboard_leaderboard), counter);
        }
    }
    if (counter == 1000) {
        if (getApiClient().isConnected()) {
            Games.Achievements.unlock(getApiClient(),
                    getString(R.string.achievement_1000_clicks));
            Games.Leaderboards.submitScoreImmediate(getApiClient(), getString(R.string.leaderboard_leaderboard), counter);
        }
    }
    if (counter == 1500) {
        if (getApiClient().isConnected()) {
            Games.Achievements.unlock(getApiClient(),
                    getString(R.string.achievement_1500_clicks));
            Games.Leaderboards.submitScoreImmediate(getApiClient(), getString(R.string.leaderboard_leaderboard), counter);
        }
    }
    if (counter == 3000) {
        if (getApiClient().isConnected()) {
            Games.Achievements.unlock(getApiClient(),
                    getString(R.string.achievement_3000_clicks));
            Games.Leaderboards.submitScoreImmediate(getApiClient(), getString(R.string.leaderboard_leaderboard), counter);
        }
    }
    if (counter == 5000) {
        if (getApiClient().isConnected()) {
            Games.Achievements.unlock(getApiClient(),
                    getString(R.string.achievement_5000_clicks));
            Games.Leaderboards.submitScore(getApiClient(), getString(R.string.leaderboard_leaderboard), counter);
        }
    }
}

XP不是基于你的游戏,而是基于你的Google+档案。假设你在游戏中解锁了一项成就,你的Google+档案中有500xp。之后,您将解锁游戏中的一项成就并获得1000xp。所以你的Google+档案总共有1500xp

但是您可以自己轻松计算XP并将其存储在:)

当你获得游戏内成就时,你可以获得经验点(XP) 在您的游戏配置文件中设置和级别

当你在玩游戏时,你会看到一个通知,当你 获得XP或足够的积分来升级游戏档案。什么时候 升级后,您还会在移动设备的 屏幕顶部附近的通知阴影和您的游戏 收件箱菜单

您可以在使用的游戏上查看XP和个人成就 在“玩游戏”个人资料页上玩游戏

有关如何公开游戏配置文件的更多信息,请参见 private,在您的设备上玩游戏


如果我的答案已经解决了你的问题,请考虑通过点击复选标记来接受它。这向更广泛的社区表明,你已经找到了一个解决方案,并给回答者和你自己带来了一些声誉。没有义务这么做。@SimonSchubert你真是个救命恩人谢谢你!真是太好了@西蒙舒伯特,但现在是crashing@SimonSchubert它现在显示此错误发送崩溃报告时出错ait:服务器未收到报告:源错误消息:中未使用移动崩溃和性能报告API项目admob-app-id-6652174517-638fe之前或禁用之前。
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();
}