playgameservices / android-basic-samples

Google Play game services - Android samples
Apache License 2.0
971 stars 973 forks source link

Task result of incrementImmediate does not return the correct unlock status. #285

Open martin-braun opened 5 years ago

martin-braun commented 5 years ago

Hi,

I've spotted a bug in AchievementsClient.incrementImmediate.

The documentation states:

This form of the API will attempt to update the user's achievement on the server immediately. The Boolean in a successful response indicates whether the achievement is now unlocked.

However, it always returns false, even when the achievement becomes unlocked. This is my code:

boolean result = false;
boolean unlocked = false;

// In a function:
Games.getAchievementsClient(GoogleSignIn.getLastSignedInAccount(this)).incrementImmediate("123456789", 1).addOnCompleteListener(new OnCompleteListener<Boolean>() {
    @Override
    public void onComplete(@NonNull Task<Boolean> task) {
        if(task.isSuccessful()) {
            result = true;
            unlocked = task.getResult(); // BUG: This is always false, even when the achievement is unlocked now
        } else {
            result = false;
            unlocked = false;
            Exception ex = task.getException();
            Log.d(TAG, "Failed to increment achievement progress: " + (ex != null ? ex.getMessage() : "UNKNOWN"));
        }
    }
});