管理中心
我的

日落公告:HMS Toolkit服务当前已不再进行版本更新。中国区域的服务将在2026-11-30日落下线,日落后将不再提供服务。

指南HMS Toolkit使用指导Convertor手工转换指导书Game Service手工转换指导书

Game Service手工转换指导书

本文导读
展开章节

开发准备

  1. 您若需要应用拥有游戏服务相关功能,必须完成开发准备。
  2. 开发前请完成开发前自检。

commitAndClose(Snapshot snapshot, SnapshotMetadataChange metadataChange)

ArchiveDetails:存档详情

summaryUpdate:存档摘要更新数据

isSupportCache:是否支持缓存数据

展开

Google API

To HMS API

commitAndClose(Snapshot snapshot,SnapshotMetadataChange metadataChange)

addArchive(ArchiveDetails details,ArchiveSummaryUpdate update,boolean isSupportCache)

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. boolean isSupportCache = false;//该值由您设置
  2. ArchivesClient archivesClient = Games.getArchiveClient(this);
  3. ArchiveSummaryUpdate archiveSummaryUpdate = null;//该值由您提前获取
  4. ArchiveDetails archiveDetails = new ArchiveDetails.Builder().build();
  5. Task<ArchiveSummary> task = archivesClient.addArchive(archiveDetails, archiveSummaryUpdate, isSupportCache);
  6. task.addOnSuccessListener(new OnSuccessListener<ArchiveSummary>() {
  7. @Override
  8. public void onSuccess(ArchiveSummary archiveSummary) {
  9. if (archiveSummary != null) {
  10. String content = "archiveId:" + archiveSummary.getId();
  11. Log.i("Archive", content);
  12. }
  13. }
  14. }).addOnFailureListener(new OnFailureListener() {
  15. @Override
  16. public void onFailure(Exception e) {
  17. ApiException apiException = (ApiException) e;
  18. String content = "add result:" + apiException.getStatusCode();
  19. Log.e("Archive", content);
  20. }
  21. });

delete(GoogleApiClient apiClient, SnapshotMetadata metadata)

展开

Google API

To HMS API

delete(GoogleApiClient apiClient, SnapshotMetadata metadata)

removeArchive(ArchiveSummary summary)

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. ArchiveSummary archiveSummary = null;//该值由您提前获取
  2. ArchivesClient client = Games.getArchiveClient(this);
  3. Task<String> task = client.removeArchive(archiveSummary);
  4. task.addOnSuccessListener(new OnSuccessListener<String>() {
  5. @Override
  6. public void onSuccess(String s) {
  7. Log.i("Archive", "delete success, archiveId:" + s);
  8. }
  9. }).addOnFailureListener(new OnFailureListener() {
  10. @Override
  11. public void onFailure(Exception e) {
  12. if (e instanceof ApiException) {
  13. ApiException apiException = (ApiException) e;
  14. Log.e("Archive", "delete failed, statusCode:" + apiException.getStatusCode());
  15. }
  16. }
  17. });

getAchievementsIntent(GoogleApiClient apiClient)

展开

Google API

To HMS API

Intent getAchievementsIntent(GoogleApiClient apiClient)

Task<Intent> getShowAchievementListIntent()

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. AchievementsClient client = Games.getAchievementsClient(this);
  2. Task<Intent> task = client.getShowAchievementListIntent();
  3. task.addOnSuccessListener(new OnSuccessListener<Intent>() {
  4. @Override
  5. public void onSuccess(Intent intent) {
  6. if (intent == null) {
  7. Log.w("Achievement", "intent = null");
  8. } else {
  9. try {
  10. startActivityForResult(intent, 1000);
  11. } catch (Exception e) {
  12. Log.e("Achievement", "Achievement Activity is Invalid");
  13. }
  14. }
  15. }
  16. }).addOnFailureListener(new OnFailureListener() {
  17. @Override
  18. public void onFailure(Exception e) {
  19. if (e instanceof ApiException) {
  20. String result = "rtnCode:" + ((ApiException) e).getStatusCode();
  21. Log.e("Achievement", "result:" + result);
  22. }
  23. }
  24. });

getCurrentPlayerId(GoogleApiClient apiClient)

展开

Google API

To HMS API

String getCurrentPlayerId(GoogleApiClient apiClient)

Task<String> getCachePlayerId()

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. PlayersClient client = Games.getPlayersClient(this);
  2. Task<String> task = client.getCachePlayerId();
  3. task.addOnSuccessListener(new OnSuccessListener<String>() {
  4. @Override
  5. public void onSuccess(String playerId) {
  6. Log.i("Player", playerId);
  7. }
  8. }).addOnFailureListener(new OnFailureListener() {
  9. @Override
  10. public void onFailure(Exception e) {
  11. if (e instanceof ApiException) {
  12. String result = "rtnCode:" + ((ApiException) e).getStatusCode();
  13. Log.e("Player", "result:" + result);
  14. }
  15. }
  16. });

getLevelInfo()

展开

Google API

To HMS API

PlayerLevelInfo getLevelInfo()

int getLevel()

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. int playerLevel = player.getLevel();

getMaxCoverImageSize(GoogleApiClient apiClient, String id)

展开

Google API

To HMS API

int getMaxCoverImageSize(GoogleApiClient apiClient, String id)

Task<Integer> getLimitThumbnailSize()

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. Task<Integer> task = Games.getArchiveClient(this).getLimitThumbnailSize();
  2. task.addOnSuccessListener(new OnSuccessListener<Integer>() {
  3. @Override
  4. public void onSuccess(Integer integer) {
  5. Log.i("Archive", "Limit thumbnail size:" + integer);
  6. }
  7. }).addOnFailureListener(new OnFailureListener() {
  8. @Override
  9. public void onFailure(Exception e) {
  10. String result = "MaxData rtnCode:" + ((ApiException) e).getStatusCode();
  11. Log.e("Archive", "get Limit thumbnail failed:" + result);
  12. }
  13. });

getMaxDataSize(GoogleApiClient apiClient, String id)

展开

Google API

To HMS API

int getMaxDataSize(GoogleApiClient apiClient, String id)

Task<Integer> getLimitDetailsSize()

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. Task<Integer> task = Games.getArchiveClient(this).getLimitDetailsSize();
  2. task.addOnSuccessListener(new OnSuccessListener<Integer>() {
  3. @Override
  4. public void onSuccess(Integer integer) {
  5. Log.i("Archive", "Limit details:" + integer);
  6. }
  7. }).addOnFailureListener(new OnFailureListener() {
  8. @Override
  9. public void onFailure(Exception e) {
  10. String result = "MaxData rtnCode:" + ((ApiException) e).getStatusCode();
  11. Log.e("Archive", "get Limit details failed:" + result);
  12. }
  13. });

getSelectSnapshotIntent(GoogleApiClient, String, boolean, boolean ,int)

展开

Google API

To HMS API

Intent getSelectSnapshotIntent(GoogleApiClient,String title, boolean allowAddButton, boolean allowDeleteBtn, int maxArchive)

Task<Intent> getShowArchiveListIntent(String title, boolean allowAddButton, boolean allowDeleteBtn, int maxArchive)

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. String title = "title";//该值由您设置
  2. boolean allowAddBtn = true;//该值由您设置
  3. boolean allowDeleteBtn = true;//该值由您设置
  4. int maxArchive = 1;//该值由您设置
  5. Task<Intent> task = Games.getArchiveClient(this).getShowArchiveListIntent(title, allowAddBtn, allowDeleteBtn, maxArchive);
  6. task.addOnSuccessListener(new OnSuccessListener<Intent>() {
  7. @Override
  8. public void onSuccess(Intent intent) {
  9. if (intent == null) {
  10. Log.w("Archive", "intent = null");
  11. } else {
  12. try {
  13. startActivityForResult(intent, 2000);
  14. } catch (Exception e) {
  15. Log.e("Archive", "Archive Activity is Invalid");
  16. }
  17. }
  18. }
  19. }).addOnFailureListener(new OnFailureListener() {
  20. @Override
  21. public void onFailure(Exception e) {
  22. if (e instanceof ApiException) {
  23. String result = "rtnCode:" + ((ApiException) e).getStatusCode();
  24. Log.e("Archive", "result:" + result);
  25. }
  26. }
  27. });

getSnapshotFromBundle(Bundle bundle)

展开

Google API

To HMS API

getSnapshotFromBundle(Bundle bundle)

parseSummary(Bundle bundle)

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. Bundle bundle = new Bundle();//该值由您提前获取
  2. ArchivesClient client = Games.getArchiveClient(this);
  3. Task<ArchiveSummary> task = client.parseSummary(bundle);
  4. task.addOnSuccessListener(new OnSuccessListener<ArchiveSummary>() {
  5. @Override
  6. public void onSuccess(ArchiveSummary archiveSummary) {
  7. if (archiveSummary != null) {
  8. Log.i("Archive", "FileName:" + archiveSummary.getFileName());
  9. Log.i("Archive", "Id:" + archiveSummary.getId());
  10. Log.i("Archive", "DescInfo:" + archiveSummary.getDescInfo());
  11. Log.i("Archive", "UpdateTime:" + archiveSummary.getRecentUpdateTime());
  12. Log.i("Archive", "ActiveTime:" + archiveSummary.getActiveTime());
  13. Log.i("Archive", "ThumbnailRatio:" + archiveSummary.getThumbnailRatio());
  14. Log.i("Archive", "currentProgress:" + archiveSummary.getCurrentProgress());
  15. Log.i("Archive", "ThumbnailUri:" + archiveSummary.hasThumbnail());
  16. }
  17. }
  18. }).addOnFailureListener(new OnFailureListener() {
  19. @Override
  20. public void onFailure(Exception e) {
  21. if (e instanceof ApiException) {
  22. String result = "rtnCode:" + ((ApiException) e).getStatusCode();
  23. Log.e("Archive", result);
  24. }
  25. }
  26. });

incrementImmediate(GoogleApiClient apiClient, String id, int numSteps)

展开

Google API

To HMS API

incrementImmediate(GoogleApiClient apiClient, String id, int numSteps)

growWithResult(String id, int numSteps)

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. String id = "id";//该值由您设置
  2. int steps = 1;//该值由您设置
  3. AchievementsClient client = Games.getAchievementsClient(this);
  4. Task<Boolean> task = client.growWithResult(id, steps);
  5. task.addOnSuccessListener(new OnSuccessListener<Boolean>() {
  6. @Override
  7. public void onSuccess(Boolean isSucess) {
  8. if (isSucess) {
  9. Log.i("Achievement", "grow success");
  10. } else {
  11. Log.i("Achievement", "achievement can not grow");
  12. }
  13. }
  14. }).addOnFailureListener(new OnFailureListener() {
  15. @Override
  16. public void onFailure(Exception e) {
  17. if (e instanceof ApiException) {
  18. String result = "rtnCode:" + ((ApiException) e).getStatusCode();
  19. Log.e("Achievement", result);
  20. }
  21. }
  22. });

loadByIds(GoogleApiClient apiClient, boolean forceReload, String... eventIds)

展开

Google API

To HMS API

loadByIds(GoogleApiClient apiClient, boolean forceReload, String... eventIds)

getEventListByIds(boolean forceReload,String[] eventIds)

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. boolean forceReload = true;//该值由您设置
  2. String[] eventIds = null;//该值由您设置
  3. EventsClient client = Games.getEventsClient(this);
  4. Task<List<Event>> task = client.getEventListByIds(forceReload, eventIds);
  5. task.addOnSuccessListener(new OnSuccessListener<List<Event>>() {
  6. @Override
  7. public void onSuccess(List<Event> data) {
  8. Iterator<Event> iterator = data.iterator();
  9. }
  10. }).addOnFailureListener(new OnFailureListener() {
  11. @Override
  12. public void onFailure(Exception e) {
  13. if (e instanceof ApiException) {
  14. String result = "rtnCode:" + ((ApiException) e).getStatusCode();
  15. Log.e("Event", result);
  16. }
  17. }
  18. });

loadMoreScores(LeaderboardScoreBuffer,int,int)

  • rankingId:排行榜id
  • offsetPlayerRank:从某个排名开始取偏移,根据数据方向取值,大于0
  • maxResults:每页最大数量
  • pageDirection:数据方向(下一页,偏移的排行名次的向下:0、上一页:1,无翻页:-1)
  • timeDimension:时间维度(日:0、周:1、全部:2)
展开

Google API

To HMS API

loadMoreScores(LeaderboardScoreBuffer buffer, int maxResults, int pageDirection)

getMoreRankingScores(String rankingId, long offsetPlayerRank,int maxResults, int pageDirection, int timeDimension)

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. RankingsClient client = Games.getRankingsClient(this);
  2. Task<RankingsClient.RankingScores> task = client.getMoreRankingScores("rankingId", 1, 20, 1, 2);
  3. task.addOnFailureListener(new OnFailureListener() {
  4. @Override
  5. public void onFailure(Exception e) {
  6. Log.e("Ranking", "failure. exception: " + e);
  7. }
  8. });
  9. task.addOnSuccessListener(new OnSuccessListener<RankingsClient.RankingScores>() {
  10. @Override
  11. public void onSuccess(RankingsClient.RankingScores s) {
  12. Log.i("Ranking", " success. ");
  13. }
  14. });

loadPlayerCenteredScores(String,int,int,int)

  • rankingId:排行榜id
  • timeDimension:时间维度(日:0、周:1、全部:2)
  • maxResults:每页最大数量
  • offsetPlayerRank:从某个排名开始取偏移,根据数据方向取值,大于0
  • pageDirection:数据方向(下一页,偏移的排行名次的向下:0,上一页:1,无翻页:-1)
展开

Google API

To HMS API

loadPlayerCenteredScores(String leaderboardId, int span, int leaderboardCollection, int maxResults)

getPlayerCenteredRankingScores(String rankingId, int timeDimension,int maxResults, long offsetPlayerRank, int pageDirection)

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. RankingsClient client = Games.getRankingsClient(this);
  2. Task<RankingsClient.RankingScores> task = client.getPlayerCenteredRankingScores("rankingId", 1, 20, 1, 1);
  3. task.addOnFailureListener(new OnFailureListener() {
  4. @Override
  5. public void onFailure(Exception e) {
  6. Log.e("Ranking", " failure. exception: " + e);
  7. }
  8. });
  9. task.addOnSuccessListener(new OnSuccessListener<RankingsClient.RankingScores>() {
  10. @Override
  11. public void onSuccess(RankingsClient.RankingScores s) {
  12. Log.i("Ranking", " success");
  13. }
  14. });

loadPlayerStats(GoogleApiClient apiClient, boolean forceReload)

forceReload:是获取联网数据还是缓存数据(联网:true,不联网:false)

展开

Google API

To HMS API

loadPlayerStats(GoogleApiClient apiClient, boolean forceReload)

getGamePlayerStatistics(boolean forceReload)

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. GamePlayerStatisticsClient playerStatsClient = Games.getGamePlayerStatsClient(this);
  2. // 是否从服务端获取
  3. boolean isRealTime = false;
  4. Task<GamePlayerStatistics> task = playerStatsClient.getGamePlayerStatistics(isRealTime);
  5. task.addOnSuccessListener(new OnSuccessListener<GamePlayerStatistics>() {
  6. @Override
  7. public void onSuccess(GamePlayerStatistics playerStats) {
  8. StringBuilder sb = new StringBuilder();
  9. sb.append("AverageOnlineMinutes: " + playerStats.getAverageOnLineMinutes());
  10. sb.append("DaysFromLastGame: " + playerStats.getDaysFromLastGame());
  11. sb.append("PaymentTimes: " + playerStats.getPaymentTimes());
  12. sb.append("OnlineTimes: " + playerStats.getOnlineTimes());
  13. sb.append("TotalPurchasesAmountRange: " + playerStats.getTotalPurchasesAmountRange());
  14. Log.i("Ranking", "Result:" + sb.toString());
  15. }
  16. }).addOnFailureListener(new OnFailureListener() {
  17. @Override
  18. public void onFailure(Exception e) {
  19. if (e instanceof ApiException) {
  20. String result = "rtnCode:" + ((ApiException) e).getStatusCode();
  21. Log.e("Ranking", result);
  22. }
  23. }
  24. });

loadTopScores(String leaderboardId, int span, int leaderboardCollection, int maxResults)

isRealTime:是获取联网数据还是缓存数据(联网:true,不联网:false)

展开

Google API

To HMS API

loadTopScores(String leaderboardId, int span, int leaderboardCollection, int maxResults)

getRankingTopScores(String rankingId, int demension, int maxResults, boolean isRealTime)

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. String rankingId = "rankingId";//该值由您设置
  2. RankingsClient client = Games.getRankingsClient(this);
  3. Task<RankingsClient.RankingScores> task = client.getRankingTopScores(rankingId, 20, 1, true);
  4. task.addOnFailureListener(new OnFailureListener() {
  5. @Override
  6. public void onFailure(Exception e) {
  7. Log.e("Ranking", " failure. exception: " + e);
  8. }
  9. });
  10. task.addOnSuccessListener(new OnSuccessListener<RankingsClient.RankingScores>() {
  11. @Override
  12. public void onSuccess(RankingsClient.RankingScores s) {
  13. Log.i("Ranking", " success. ");
  14. }
  15. });

open(GoogleApiClient apiClient, SnapshotMetadata metadata)

展开

Google API

To HMS API

open(GoogleApiClient apiClient, SnapshotMetadata metadata)

loadArchiveDetails(ArchiveSummary archiveSummary)

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. String summary = "summary";//该值由您设置
  2. ArchiveSummary archiveSummary = null;//该值由您提前获取
  3. ArchivesClient client = Games.getArchiveClient(this);
  4. Task<OperationResult> task = client.loadArchiveDetails(summary);
  5. task.addOnSuccessListener(new OnSuccessListener<OperationResult>() {
  6. @Override
  7. public void onSuccess(OperationResult result) {
  8. if (result != null && !result.isDifference()) {
  9. Archive archive = result.getArchive();
  10. if (archive != null && archive.getSummary() != null) {
  11. Log.i("Archive", "loadArchiveDetails success");
  12. }
  13. }
  14. }
  15. }).addOnFailureListener(new OnFailureListener() {
  16. @Override
  17. public void onFailure(Exception e) {
  18. ApiException apiException = (ApiException) e;
  19. Log.i("Archive", "loadArchiveDetails failed");
  20. }
  21. });

open(GoogleApiClient apiClient, SnapshotMetadata metadata, int conflictPolicy)

展开

Google API

To HMS API

open(GoogleApiClient apiClient, SnapshotMetadata metadata, int conflictPolicy)

loadArchiveDetails(String archiveId, int strategy)

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. String archiveId = "archiveId";//该值由您设置
  2. int conflictPolicy = 1;//该值由您设置
  3. ArchivesClient client = Games.getArchiveClient(this);
  4. Task<OperationResult> task = client.loadArchiveDetails(archiveId, conflictPolicy);
  5. task.addOnSuccessListener(new OnSuccessListener<OperationResult>() {
  6. @Override
  7. public void onSuccess(OperationResult result) {
  8. if (result != null && !result.isDifference()) {
  9. Archive archive = result.getArchive();
  10. if (archive != null && archive.getSummary() != null) {
  11. Log.i("Archive", "loadArchiveDetails success");
  12. }
  13. }
  14. }
  15. }).addOnFailureListener(new OnFailureListener() {
  16. @Override
  17. public void onFailure(Exception e) {
  18. ApiException apiException = (ApiException) e;
  19. Log.i("Archive", "loadArchiveDetails failed");
  20. }
  21. });

open(GoogleApiClient apiClient, String fileName, boolean createIfNotFound)

展开

Google API

To HMS API

open(GoogleApiClient apiClient, String fileName, boolean createIfNotFound)

loadArchiveDetails(String archiveId)

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. String archiveId = "archiveId";//该值由您设置
  2. ArchivesClient client = Games.getArchiveClient(this);
  3. Task<OperationResult> task = client.loadArchiveDetails(archiveId);
  4. task.addOnSuccessListener(new OnSuccessListener<OperationResult>() {
  5. @Override
  6. public void onSuccess(OperationResult result) {
  7. if (result != null && !result.isDifference()) {
  8. Archive archive = result.getArchive();
  9. if (archive != null && archive.getSummary() != null) {
  10. Log.i("Archive", "loadArchiveDetails success");
  11. }
  12. }
  13. }
  14. }).addOnFailureListener(new OnFailureListener() {
  15. @Override
  16. public void onFailure(Exception e) {
  17. ApiException apiException = (ApiException) e;
  18. Log.e("Archive", "loadArchiveDetails failed");
  19. }
  20. });

open(GoogleApiClient apiClient, String fileName, boolean createIfNotFound, int conflictPolicy)

展开

Google API

To HMS API

open(GoogleApiClient apiClient, String fileName, boolean createIfNotFound, int conflictPolicy)

loadArchiveDetails(String archiveId, int diffStrategy)

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. String archiveId = "archiveId";//该值由您设置
  2. int conflictPolicy = 1;//该值由您设置
  3. ArchivesClient client = Games.getArchiveClient(this);
  4. Task<OperationResult> task = client.loadArchiveDetails(archiveId, conflictPolicy);
  5. task.addOnSuccessListener(new OnSuccessListener<OperationResult>() {
  6. @Override
  7. public void onSuccess(OperationResult result) {
  8. if (result != null && !result.isDifference()) {
  9. Archive archive = result.getArchive();
  10. if (archive != null && archive.getSummary() != null) {
  11. Log.i("Archive", "loadArchiveDetails success");
  12. }
  13. }
  14. }
  15. }).addOnFailureListener(new OnFailureListener() {
  16. @Override
  17. public void onFailure(Exception e) {
  18. ApiException apiException = (ApiException) e;
  19. Log.i("Archive", "loadArchiveDetails failed");
  20. }
  21. });

PendingResult<Achievements.LoadAchievementsResult> load(GoogleApiClient apiClient, boolean forceReload)

isRealTime:是获取联网数据还是缓存数据(联网:true,不联网:false)

展开

Google API

To HMS API

load(GoogleApiClient apiClient, boolean forceReload)

getAchievementList(boolean forceReload)

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. AchievementsClient client = Games.getAchievementsClient(this);
  2. boolean forceReload = true;//该值由您设置
  3. Task<List<Achievement>> task = client.getAchievementList(forceReload);
  4. task.addOnSuccessListener(new OnSuccessListener<List<Achievement>>() {
  5. @Override
  6. public void onSuccess(List<Achievement> data) {
  7. if (data == null) {
  8. return;
  9. }
  10. Iterator<Achievement> iterator = data.iterator();
  11. while (iterator.hasNext()) {
  12. Achievement achievement = iterator.next();
  13. Player player = achievement.getGamePlayer();
  14. }
  15. }
  16. }).addOnFailureListener(new OnFailureListener() {
  17. @Override
  18. public void onFailure(Exception e) {
  19. if (e instanceof ApiException) {
  20. String result = "rtnCode:" + ((ApiException) e).getStatusCode();
  21. Log.e("Achievement", "result:" + result);
  22. }
  23. }
  24. });

PendingResult<Events.LoadEventsResult> load(GoogleApiClient apiClient, boolean forceReload)

展开

Google API

To HMS API

load(GoogleApiClient apiClient, boolean forceReload)

getEventList(boolean forceReload)

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. boolean forceReload = true;//该值由您设置
  2. EventsClient client = Games.getEventsClient(this);
  3. Task<List<Event>> task = client.getEventList(forceReload);
  4. task.addOnSuccessListener(new OnSuccessListener<List<Event>() {
  5. @Override
  6. public void onSuccess(List<Event> data) {
  7. if (data == null) {
  8. Log.i("Event", "data is null");
  9. return;
  10. }
  11. Iterator<Event> iterator = data.iterator();
  12. }
  13. }).addOnFailureListener(new OnFailureListener() {
  14. @Override
  15. public void onFailure(Exception e) {
  16. if (e instanceof ApiException) {
  17. String result = "rtnCode:" + ((ApiException) e).getStatusCode();
  18. Log.e("Event", "result:" + result);
  19. }
  20. }
  21. });

PendingResult<Snapshots.LoadSnapshotsResult> load(GoogleApiClient apiClient, boolean forceReload)

展开

Google API

To HMS API

load(GoogleApiClient apiClient, boolean forceReload)

getArchiveSummaryList(boolean isRealName)

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. boolean isRealTime = true;//该值由您设置
  2. ArchivesClient client = Games.getArchiveClient(this);
  3. Task<List<ArchiveSummary>> task = client.getArchiveSummaryList(isRealTime);
  4. task.addOnSuccessListener(new OnSuccessListener<List<ArchiveSummary>>() {
  5. @Override
  6. public void onSuccess(List<ArchiveSummary> data) {
  7. if (data == null) {
  8. return;
  9. }
  10. Log.i("Archive ", "get archive list success");
  11. }
  12. }).addOnFailureListener(new OnFailureListener() {
  13. @Override
  14. public void onFailure(Exception e) {
  15. if (e instanceof ApiException) {
  16. String result = "rtnCode:" + ((ApiException) e).getStatusCode();
  17. Log.e("Archive", "result:" + result);
  18. }
  19. }
  20. });

Player getCurrentPlayer(GoogleApiClient apiClient)

展开

Google API

To HMS API

Player getCurrentPlayer(GoogleApiClient apiClient)

Task<Player> getCurrentPlayer()

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. PlayersClient client = Games.getPlayersClient(this);
  2. Task<Player> task = client.getCurrentPlayer();
  3. task.addOnSuccessListener(new OnSuccessListener<Player>() {
  4. @Override
  5. public void onSuccess(Player player) {
  6. Log.i("Player", player.getDisplayName());
  7. }
  8. }).addOnFailureListener(new OnFailureListener() {
  9. @Override
  10. public void onFailure(Exception e) {
  11. if (e instanceof ApiException) {
  12. String result = "rtnCode:" + ((ApiException) e).getStatusCode();
  13. Log.e("Player", "result:" + result);
  14. }
  15. }
  16. });

PlayerStats getPlayerStats()

展开

Google API

To HMS API

PlayerStats getPlayerStats()

Task<GamePlayerStatistics> getGamePlayerStatistics(boolean isRealTime)

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. boolean isRealTime = true;//该值由您设置
  2. GamePlayerStatisticsClient playerStatsClient = Games.getGamePlayerStatsClient(this);
  3. Task<GamePlayerStatistics> task = playerStatsClient.getGamePlayerStatistics(isRealTime);
  4. task.addOnSuccessListener(new OnSuccessListener<GamePlayerStatistics>() {
  5. @Override
  6. public void onSuccess(GamePlayerStatistics gamePlayerStatistics) {
  7. if (gamePlayerStatistics == null) {
  8. Log.i("gamePlayerStatistics", "playerStatsAnnotatedData is null, inner error");
  9. return;
  10. }
  11. StringBuilder sb = new StringBuilder();
  12. sb.append("IsRealTime:" + ISREALTIME);
  13. sb.append("\n---AverageSessionLength: " + gamePlayerStatistics.getAverageOnLineMinutes() + "\n---");
  14. sb.append("DaysSinceLastPlayed: " + gamePlayerStatistics.getDaysFromLastGame() + "\n---");
  15. sb.append("NumberOfPurchases: " + gamePlayerStatistics.getPaymentTimes() + "\n---");
  16. sb.append("NumberOfSessions: " + gamePlayerStatistics.getOnlineTimes() + "\n---");
  17. sb.append("TotalPurchasesAmountRange: " + gamePlayerStatistics.getTotalPurchasesAmountRange());
  18. Log.i("gamePlayerStatistics",sb.toString());
  19. }
  20. }).addOnFailureListener(new OnFailureListener() {
  21. @Override
  22. public void onFailure(Exception e) {
  23. if (e instanceof ApiException) {
  24. String result = "rtnCode:" + ((ApiException) e).getStatusCode();
  25. Log.i("gamePlayerStatistics",result);
  26. }
  27. }
  28. });

resolveConflict(GoogleApiClient apiClient, String conflictId, Snapshot snapshot)

展开

Google API

To HMS API

resolveConflict(GoogleApiClient apiClient, String conflictId, Snapshot snapshot)

updateArchive(Archive archive)

方法参考:

收起
自动换行
深色代码主题
复制
  1. Archive archive = null;//该值由您提前获取
  2. ArchivesClient client = Games.getArchiveClient(this);
  3. Task<OperationResult> task =
  4. client.updateArchive(archive);
  5. task.addOnSuccessListener(new OnSuccessListener<OperationResult>() {
  6. @Override
  7. public void onSuccess(OperationResult result) {
  8. if (result != null && !result.isDifference()) {
  9. Archive archive = result.getArchive();
  10. if (archive != null && archive.getSummary() != null) {
  11. Log.i("Archive", "update archive success");
  12. }
  13. }
  14. }
  15. }).addOnFailureListener(new OnFailureListener() {
  16. @Override
  17. public void onFailure(Exception e) {
  18. ApiException apiException = (ApiException) e;
  19. Log.e("Archive ", "update result:" + apiException.getStatusCode());
  20. }
  21. });

resolveConflict(GoogleApiClient apiClient, String conflictId,String snapshotId, SnapshotMetadataChange metadataChange, SnapshotContents snapshotContents)

展开

Google API

To HMS API

resolveConflict(GoogleApiClient apiClient, String conflictId,String snapshotId, SnapshotMetadataChange metadataChange, SnapshotContents snapshotContents)

updateArchive(String id,ArchiveSummaryUpdate summaryUpdate,ArchiveDetails details)

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. String id = "id";//该值由您设置
  2. ArchiveSummaryUpdate archiveSummaryUpdate = null;//该值由您提前获取
  3. ArchiveDetails archiveDetails = null;//该值由您提前获取
  4. ArchivesClient client = Games.getArchiveClient(this);
  5. Task<OperationResult> task =
  6. client.updateArchive(id, archiveSummaryUpdate, archiveDetails);
  7. task.addOnSuccessListener(new OnSuccessListener<OperationResult>() {
  8. @Override
  9. public void onSuccess(OperationResult result) {
  10. if (result != null && !result.isDifference()) {
  11. Archive archive = result.getArchive();
  12. if (archive != null && archive.getSummary() != null) {
  13. Log.i("Archive", archive.getSummary().getId());
  14. }
  15. }
  16. }
  17. }).addOnFailureListener(new OnFailureListener() {
  18. @Override
  19. public void onFailure(Exception e) {
  20. ApiException apiException = (ApiException) e;
  21. Log.e("Archive", "update failed");
  22. }
  23. });

revealImmediate(GoogleApiClient apiClient, String id)

展开

Google API

To HMS API

revealImmediate(GoogleApiClient apiClient, String id)

visualizeWithResult(String id)

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. String id = "id";//该值由您设置
  2. AchievementsClient client = Games.getAchievementsClient(this);
  3. Task<Void> task = client.visualizeWithResult(id);
  4. task.addOnSuccessListener(new OnSuccessListener<Void>() {
  5. @Override
  6. public void onSuccess(Void v) {
  7. Log.i("Achievement", "visualize success");
  8. }
  9. }).addOnFailureListener(new OnFailureListener() {
  10. @Override
  11. public void onFailure(Exception e) {
  12. if (e instanceof ApiException) {
  13. String result = "rtnCode:" + ((ApiException) e).getStatusCode();
  14. Log.e("Achievement", "visualize failed:" + result);
  15. }
  16. }
  17. });

setStepsImmediate(GoogleApiClient apiClient,String id, int numSteps)

展开

Google API

To HMS API

setStepsImmediate(GoogleApiClient apiClient,String id, int numSteps)

makeStepsWithResult(String id, int numSteps)

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. String achievementId = "id";//该值由您设置
  2. int numSteps = 1;//该值由您设置
  3. AchievementsClient client = Games.getAchievementsClient(this);
  4. Task<Boolean> task = client.makeStepsWithResult(achievementId, numSteps);
  5. task.addOnSuccessListener(new OnSuccessListener<Boolean>() {
  6. @Override
  7. public void onSuccess(Boolean isSucess) {
  8. Log.i("Achievement", "make steps result:" + isSucess);
  9. }
  10. }).addOnFailureListener(new OnFailureListener() {
  11. @Override
  12. public void onFailure(Exception e) {
  13. if (e instanceof ApiException) {
  14. String result = "rtnCode:" + ((ApiException) e).getStatusCode();
  15. Log.e("Achievement", "make steps failed:" + result);
  16. }
  17. }
  18. });

unlockImmediate(GoogleApiClient apiClient, String id)

展开

Google API

To HMS API

unlockImmediate(GoogleApiClient apiClient, String id)

reachWithResult(String id)

To HMS API方法参考:

收起
自动换行
深色代码主题
复制
  1. String achievementId = "id";//该值由您设置
  2. AchievementsClient client = Games.getAchievementsClient(this);
  3. Task<Void> task = client.reachWithResult(achievementId);
  4. task.addOnSuccessListener(new OnSuccessListener<Void>() {
  5. @Override
  6. public void onSuccess(Void v) {
  7. Log.i("Achievement", "reach success");
  8. }
  9. }).addOnFailureListener(new OnFailureListener() {
  10. @Override
  11. public void onFailure(Exception e) {
  12. if (e instanceof ApiException) {
  13. String result = "rtnCode:" + ((ApiException) e).getStatusCode();
  14. Log.e("Achievement", "reach failed:" + result);
  15. }
  16. }
  17. });