目录

1. Use Case

Basic game information includes the app ID, name, description, and category of your game. Your game can obtain basic game information from Huawei game server if necessary.

2. Before You Start

To use the basic game information feature, users need to enable Game Services in HUAWEI AppGallery (10.3 or later). If a user who has not enabled Game Services triggers basic game information API calling, the HMS Core SDK redirects the user to the Game Services switch screen in HUAWEI AppGallery and instructs the user to enable Game Services. If the user does not enable Game Services, result code 7018 is returned. Your game needs to actively instruct users to go to Me > Settings > Game Services in AppGallery, so the basic game information feature will be available.

Note:
You are advised to provide the function for users who have enabled Game Services to disable it. Call GamesClient.cancelGameService to implement the function.

3. Initializing the GameSummaryClient Instance

Before calling any game basic information API, call the Games.getGameSummaryClient method to obtain the GameSummaryClient instance.

  1. GameSummaryClient gamemetadataClient= Games.getGameSummaryClient(activity
  2. , msignInHuaweiId);

The value of mSignInHuaweiId passed in the API is the AuthHuaweiId object obtained when a user signs in to the game. If a user has not signed in, pass in null.

4. Obtaining Basic Game Information

If basic game information has been obtained before, call GameSummaryClient.getLocalGameSummary to obtain the locally cached basic game information.

  1. Task<GameSummary> task = client.getLocalGameSummary();
  2. task.addOnSuccessListener(new OnSuccessListener<GameSummary>() {
  3.    @Override
  4.    public void onSuccess(GameSummary gameSummary) {
  5.        Log.i("GameSummary", "achievementCount:" + gameSummary.getAchievementCount());
  6.        Log.i("GameSummary", "appId:" + gameSummary.getAppId());
  7.        Log.i("GameSummary", "descInfo:" + gameSummary.getDescInfo());
  8.        Log.i("GameSummary", "gameName:" + gameSummary.getGameName());
  9.        Log.i("GameSummary", "gameHdImgUri:" + gameSummary.getGameHdImgUri().toString());
  10.        Log.i("GameSummary", "gameIconUri:" + gameSummary.getGameIconUri().toString());
  11.        Log.i("GameSummary", "rankingCount:" + gameSummary.getRankingCount());
  12.        Log.i("GameSummary", "firstKind:" + gameSummary.getFirstKind());
  13.        Log.i("GameSummary", "secondKind:" + gameSummary.getSecondKind());
  14.    }
  15. }).addOnFailureListener(new OnFailureListener() {
  16.    @Override
  17.    public void onFailure(Exception e) {
  18.        if (e instanceof ApiException) {
  19.            String result = "rtnCode:" + ((ApiException) e).getStatusCode();
  20.            Log.w("GameSummary", result);
  21.        }
  22.    }
  23. });

If basic game information has not been obtained before, call GameSummaryClient.getGameSummary to obtain the information from Huawei game server.

  1. Task<GameSummary> task = client.getGameSummary();
  2. task.addOnSuccessListener(new OnSuccessListener<GameSummary>() {
  3.    @Override
  4.    public void onSuccess(GameSummary gameSummary) {

  1.        Log.i("GameSummary", "achievementCount:" + gameSummary.getAchievementCount());
  2.        Log.i("GameSummary", "appId:" + gameSummary.getAppId());
  3.        Log.i("GameSummary", "descInfo:" + gameSummary.getDescInfo());
  4.        Log.i("GameSummary", "gameName:" + gameSummary.getGameName());
  5.        Log.i("GameSummary", "gameHdImgUri:" + gameSummary.getGameHdImgUri().toString());
  6.        Log.i("GameSummary", "gameIconUri:" + gameSummary.getGameIconUri().toString());
  7.        Log.i("GameSummary", "rankingCount:" + gameSummary.getRankingCount());
  8.        Log.i("GameSummary", "firstKind:" + gameSummary.getFirstKind());
  9.        Log.i("GameSummary", "secondKind:" + gameSummary.getSecondKind());
  10.    }
  11. }).addOnFailureListener(new OnFailureListener() {
  12.    @Override
  13.    public void onFailure(Exception e) {
  14.        if (e instanceof ApiException) {
  15.            String result = "rtnCode:" + ((ApiException) e).getStatusCode();
  16.            Log.w("GameSummary", result);
  17.        }
  18.    }
  19. });