0
votes

I implemented Android Leaderboards: https://developers.google.com/games/services/android/leaderboards

Before I was using leaderboards with BaseGameUtils, and it didn't force the user to install Google Play Games. But now after migrating to the new leaderboards, it prompts a dialog forcing to install Google Play Games app in the device for displaying the leaderboard.

This is the simple code for displaying leaderboards:

private void showLeaderboard() {
  Games.getLeaderboardsClient(this, GoogleSignIn.getLastSignedInAccount(this))
      .getLeaderboardIntent(getString(R.string.leaderboard_id))
      .addOnSuccessListener(new OnSuccessListener<Intent>() {
        @Override
        public void onSuccess(Intent intent) {
          startActivityForResult(intent, RC_LEADERBOARD_UI);
        }
      });
}
1

1 Answers

1
votes

Based from the documentation of leaderboard API:

Before you start to code using the leaderboards APIs:

  • Follow the instructions for installing and setting up your app to use Google Play games services in the Set Up Google Play Services SDK guide.
  • Define the leaderboards that you want your game to display or update, by following the instructions in the Google Play Console guide.
  • Download and review the leaderboards code samples in the Android samples page.
  • Familiarize yourself with the recommendations described in Quality Checklist.

This means that it's up to you to decide the appropriate place in your app to verify the Google Play services version. If Google services is required for your app at all times, you might want to do it when your app first launches. And if it is optional, you can check the version only once the user navigates to that portion of your app.

Another approach:

is to use the isGooglePlayServicesAvailable() method. You get a reference to the singleton object that provides this method using GoogleApiAvailability.getInstance(). You might call this method in the onResume() method of the main activity. If the result code is SUCCESS, then the Google Play services APK is up-to-date and you can continue to make a connection. If, however, the result code is SERVICE_MISSING, SERVICE_VERSION_UPDATE_REQUIRED, or SERVICE_DISABLED, then the user needs to install an update. In this case, call the getErrorDialog() method and pass it the result error code. The method returns a Dialog you should show, which provides an appropriate message about the error and provides an action that takes the user to Google Play Store to install the update.