Skip to main content

Login

Overview

The whole login process looks like

mobile_login_flow.png

Usage

Get the current login token

AccountManager.getLastLoginRecord();

Restore the status of the last login

AccountManager accountManager = new AccountManager(activity);
accountManager.restoreLogin(callback);

Log out

AccountManager accountManager = new AccountManager(activity);
accountManager.logout(success -> {
if (success) {
...
} else {
...
}
});

Log out directly regardless of whether the log-out API request is successful

AccountManager accountManager = new AccountManager(activity);
accountManager.logoutDirectly();

Get server recommendation

Make sure you've configured your game server information on the Garena Open Platform.

LoginLocationManager.getRecommendedServer(activity, locale, result->{
if(result.isSuccess()) {
RecommendedServerInfo serverInfo = result.unwrap();
String country = serverInfo.getCountry();
Strint countryCode = serverInfo.getCountryCode();
String recommendedServer = serverInfo.getRcommendedServer();
...
} else {
MSDKError error = result.getErrorInfo();
// handle error
}
});

Callback and Error Handling

You can listen to login status by OnLoginListener

    @Override
public void onSessionStatusChanged(@NonNull LoginSessionStatus status, @Nullable MSDKError error) {
if (LoginError.INVALID_TOKEN.equals(error)) {
// current user token has expired, should go back to the login page and log in again.
return;
}
if (status == LoginSessionStatus.OPENING) {
// start login
return;
}

if (AccountManager.isLogin()) {
// do something
}
}

Platform Info

Since v5.8.0.

In order to provide more precise account info when dealing with App Platform Binding and Account Security Verifier, we’ve added new properties in the LoginToken.

loginPlatform: Represents the platform used for logging into the account in the current login session. It is defined by the PlatformType enumeration. For example, if the user logs in with Garena, the value of this parameter would be Garena.

originalPlatform: Indicates the original platform associated with the user’s account, representing the initial platform of the account when the user first played the game. In the scenario where a user swaps their Garena account to a Facebook account and subsequently logs in with the Facebook account, the value of originalPlatform would be Garena.

primaryPlatform: Indicates the player’s current main active login account platform. If the login account is bound to a primary account on a specific platform, this parameter reflects the primary platform. Otherwise, it will have the same value as loginPlatform. This field corresponds to the main_active_platform field on the server side. For example, if a user logs in with a Garena account that is bound to a primary account on the Facebook platform, the value of this parameter would be Facebook.

The platformType has been deprecated.