我尝试将成就添加到我的应用中。我使用Google官方文档来使用Google Play服务。我使用signInSilently()登录Google Play游戏:
private void signInSilently() {
GoogleSignInOptions signInOptions = GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN;
GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
if (GoogleSignIn.hasPermissions(account, signInOptions.getScopeArray())) {
GoogleSignInAccount signedInAccount = account;
} else {
GoogleSignInClient signInClient = GoogleSignIn.getClient(this, signInOptions);
signInClient
.silentSignIn()
.addOnCompleteListener(
this,
task -> {
if (task.isSuccessful()) {
GoogleSignInAccount signedInAccount = task.getResult();
} else {
}
});
}
}
我这样称呼signInSilently(),即onStart():
signInSilently();
gamesClient = Games.getGamesClient(this, Objects.requireNonNull(GoogleSignIn.getLastSignedInAccount(this)));
gamesClient.setViewForPopups(findViewById(android.R.id.content));
最后两行在屏幕顶部显示授权弹出窗口,但是当我想解锁成就时:
Games.getAchievementsClient(this, Objects.requireNonNull(GoogleSignIn.getLastSignedInAccount(this)))
.unlock(getString(R.string.achievement_first_regular));
gamesClient = Games.getGamesClient(this,
Objects.requireNonNull(GoogleSignIn.getLastSignedInAccount(MainActivity.this)));
gamesClient.setViewForPopups(findViewById(android.R.id.content));
gamesClient.setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
它运作良好,已解锁,但我看不到屏幕顶部的解锁动画,就像有授权一样。 也许我需要做更多的事情吗?我已经阅读过有关google api客户端的信息,但是我没有找到有关它的很好的文档。