2
votes

I am able to log in using helper classes from BaseGameUtils: https://github.com/playgameservices/android-basic-samples/tree/master/BasicSamples/libraries/BaseGameUtils/src/main/java/com/google/example/games/basegameutils

How can I get the ID of the player just logged in?

gameHelper.setConnectOnStart(false);
gameHelper.setMaxAutoSignInAttempts(0);
gameHelper.setup(gameHelperListener);    
final GameHelper.GameHelperListener gameHelperListener = new GameHelper.GameHelperListener() {
    @Override
    public void onSignInFailed() {
    }

    @Override
    public void onSignInSucceeded() {
        // I want to get the player ID here
    } 
};

Login code:

try {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            gameHelper.beginUserInitiatedSignIn();
        }
    });
} catch (Exception e) {
}
1
Games.Players is deprecated. Please check my answer here: stackoverflow.com/questions/26413589/…Martin Braun

1 Answers

4
votes

This question was answered here: Get a user ID from Google Play Services?

Here is the solution:

String playerId = Games.Players.getCurrentPlayerId(getApiClient());