I have an application where I am implementing gamification using Google Play Games. When a user releases an achievement I need to know what is the total points this user, filtering only by my app. For example, assuming that my app tries to 10 achievements and the User has released four of them. How to know the total score generated by these 4 achievements released by the User in question? There are an easy and lightweight way to do this?
UPDATE
Well, i tried this code, but aways return zero.
public abstract class GetAchievements {
public void loadAchievements() {
PendingResult<Achievements.LoadAchievementsResult> pendingAchievements = Games.Achievements.load(mGoogleApiClient, true);
pendingAchievements.setResultCallback(new ResultCallback<Achievements.LoadAchievementsResult>() {
@Override
public void onResult(Achievements.LoadAchievementsResult loadAchievementsResult) {
Game game = Games.GamesMetadata.getCurrentGame(mGoogleApiClient);
extractAchievements(loadAchievementsResult, game);
}
});
}
public void extractAchievements(Achievements.LoadAchievementsResult loadAchievementsResult, Game game) {
AchievementBuffer buffer = loadAchievementsResult.getAchievements();
List<Achievement> achievementList = new ArrayList<>();
for (int i = 0; i < game.getAchievementTotalCount(); i++) {
achievementList.add(buffer.get(i));
Achievement a = buffer.get(i);
// aways return 0
Log.d(TAG, "XP = " + a.getXpValue());
}
notifyAchievements(achievementList);
}
public abstract void notifyAchievements(List<Achievement> achievementList);
}
You can try using Achievement
Class from com.google.android.gms.games.achievement
package.
- XP value given to players for unlocking this achievement.
Also here is document for Adding Achievements to Your Android Game:
This guide shows you how to use the achievements APIs in an Android application to unlock and display achievements in your game.
To show a player's achievements, call
getAchievementsIntent()
to get anIntent
to create the default achievements UI. Your game can then bring up the UI by calling [startActivityForResult
](https://developer.android.com/reference/android/app/Activity.html#startActivityForResult(android.content.Intent, int)). In the following snippet,REQUEST_ACHIEVEMENTS
is an arbitrary integer used as the request code.
startActivityForResult(Games.Achievements.getAchievementsIntent(mGoogleApiClient),
REQUEST_ACHIEVEMENTS);