Skip to main content

Login via Google Play Games

Prerequisite

Create a credential from Google Play Console and select an OAuth client which you created from Google Cloud Console

google_play_credential.jpg

And get the app id from

google_play_credential2.jpg

Add dependencies

Add the following code in build.gradle on the app-level, and replace $msdk_version with the actual MSDK version.

dependencies {
implementation "com.garena.sdk.android:login-pgs:$msdk_version"
}

Configuration

Configure AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

...

<application ...>

<meta-data
android:name="com.google.android.gms.games.APP_ID"
android:value="[google_play_games_app_id]" />

<meta-data
android:name="com.garena.sdk.gms.games.OAUTH_CLIENT_ID"
android:value="[google_play_games_oauth_client_id]" />

....
</application>

</manifest>

Usage

AccountManager accountManager = new AccountManager(activity);
accountManager.login(PlatformType.GOOGLE_PLAY_GAMES, onLoginListener);

Google Play Games Recall

Prerequisite

  1. Setup Google Play Games Tester Account on Google Console
  2. If you have imported the Google Play Games dependency, you need to remove the dependency
implementation "com.google.android.gms:play-services-games-v2:17.0.0"

Usage

You should call saveToken after login success (including auto-login success), so that the token on Google Play Games is up to date.

PlayGamesRecallManager recallManager = new PlayGamesRecallManager(activity);
recallManager.saveToken(result -> {...});

Checks the Google Play Games sign-in state asynchronously.

recallManager.checkSignInState(result -> {
...
});

Recall tokens and restore login

recallManager.retrieveToken(result -> {
if (result.isSuccess()) {
// Currently server only returns the last RecallToken.
// But in the future we may return multiple tokens, that's why here's a list
List<RecallToken> tokens = result.unwrap();
if (!tokens.isEmpty()) {
RecallToken recallToken = tokens.get(0);
recallManager.restoreLogin(recallToken, callback);
}
}
});