Search code examples
androidgoogle-play-servicesachievements

how to update the Incremental achievements on google play


if i got 100 steps like "play the game 100 time" and i played 50 times i can't write like that coz it wont update it till i play 100 times... so how do i update it per game?

    if (timePlayed>99) {
            Games.Achievements.unlock(getApiClient(), 
                    getString(R.string.persistant));
        }

Solution

  • First, be sure to set the achievement as incremental (with 100 steps) in the Developer Console, as follows:

    Developer Console Incremental Achievements

    Next, in your code use the Games.Achievements.increment() method instead of the unlock method.

    Games.Achievements.increment(getApiClient(), getString(R.string.persistant), 1 );
    

    Just replace the last argument (i.e. the 1 in the example above) with the amount by which to increment.

    That's it, once it reaches the amount you set in the Developer Console the achievement will be unlocked automatically (you do not need to do this manually). Additionally, each time increment is called, the percentage in the Achievements screen will be updated to reflect the change in value.

    For your purposes, you should call increment() once each time the game is started (with an increment value of 1).