Skip to content

onGetUserInfo ​

Get Basic User Information ​

This method is used to obtain the original App user information. Its main purpose: to provide non-sensitive App user information to the game.


Method Declaration ​

java
/**
 * Triggered when the SDK requests basic user information (User Info).
 * The App should return the user's nickname, avatar, and other basic information via handle in response to this request.
 *
 * @param handle   The state handle used to return the processing result to the SDK.
 * @param dataJson A JSON string containing the request parameters (such as the list of user IDs).
 */
void onGetUserInfo(SUDOPStateHandle handle);

Runtime Behavior ​

  • Trigger timing: Usually occurs during game initialization, when a player joins a room, or when tapping to view another player's brief information.
  • Standard format: The App must construct the JSON result according to the keys agreed upon in the SUDOP protocol (such as nickname, avatar).
  • Asynchronous feedback: Supports synchronizing the data to the game asynchronously via handle.success(resultJson) after the network request completes.

Example Code ​

Implement the lookup and asynchronous return of basic information:

java
@Override
public void onGetUserInfo(SUDOPStateHandle handle) {
    String userId = gameViewModel.getUserId();
    JSONObject obj = new JSONObject();
    try {
        obj.put("nickname", "this is nickname");
        obj.put("avatar", "this is avatar");
    } catch (Exception e) {
        e.printStackTrace();
    }
    handle.success(obj.toString());
}

Notes ​

  • Avatar specifications: It is recommended to provide a high-resolution avatar URL with a 1:1 aspect ratio, so the game maintains good visual quality across different UI sizes.
  • Caching strategy: For frequently requested user information, it is recommended that the App side implement caching to avoid initiating a network request every time, which could cause stuttering or loading spinners in the game.
  • Field alignment: Be sure to use the key names defined in the SUDOP constants class, to avoid the game failing to parse the data due to spelling errors.