gpt4 book ai didi

android - 使用 Google Play 游戏获得成就时不会显示弹出窗口

转载 作者:行者123 更新时间:2023-11-29 23:44:39 25 4
gpt4 key购买 nike

我发现了一堆有类似问题的帖子,但大多数都在使用我没有的 BaseGameUtilsGoogleApiClient。一个建议的答案是添加 Games.setViewForPopups(getApiClient(), findViewById(R.id.gps_popup)); 除非我有 GoogleApiClient,否则我不能这样做。

成就代码:

public void achieve(String achievement) {
Games.getAchievementsClient(this, signedInAccount).unlock(achievement);
}

public void increment(String achievement, int i) {
Games.getAchievementsClient(this, signedInAccount).increment(achievement, i);
}

登录码:

@Override
protected void onCreate(Bundle _savedInstanceState) {
...
signInSilently();
}

private void signInSilently() {
GoogleSignInClient signInClient = GoogleSignIn.getClient(this, GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
signInClient.silentSignIn().addOnCompleteListener(this,
new OnCompleteListener<GoogleSignInAccount>() {
@Override
public void onComplete(@NonNull Task<GoogleSignInAccount> task) {
if (task.isSuccessful()) {
signedInAccount = task.getResult();
findViewById(R.id.achievements_btn).setVisibility(View.VISIBLE);
} else {
startSignInIntent();
}
}
});
}

private void startSignInIntent() {
GoogleSignInClient signInClient = GoogleSignIn.getClient(this,
GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
Intent intent = signInClient.getSignInIntent();
startActivityForResult(intent, RC_SIGN_IN);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (result.isSuccess()) {
signedInAccount = result.getSignInAccount();
findViewById(R.id.achievements_btn).setVisibility(View.VISIBLE);
Toast.makeText(getApplicationContext(), "Signed In", Toast.LENGTH_SHORT).show();
} else {
String message = result.getStatus().getStatusMessage();
if (message == null || message.isEmpty()) {
message = "Error";
}
Toast.makeText(getApplicationContext(), "Sign In Failed, please check internet connection and restart the app to use achievements.", Toast.LENGTH_LONG).show();
cancelledSignIn = true;
}
}
}


private void showAchievements() {
Games.getAchievementsClient(this, signedInAccount)
.getAchievementsIntent()
.addOnSuccessListener(new OnSuccessListener<Intent>() {
@Override
public void onSuccess(Intent intent) {
startActivityForResult(intent, RC_ACHIEVEMENT_UI);
}
});
}

不知道该怎么做,除了弹出窗口从不显示外,这一切都运行良好。我从来不需要使用 GoogleApiClient,如果我确实需要,您能告诉我为什么以及如何使用吗?将不胜感激所有帮助!

最佳答案

我有同样的问题,也没有使用 BaseGameUtilsGoogleApiClient

我将以下内容添加到我的 OnConnected 来自 this StackOverflow answer .

GamesClient gamesClient = Games.getGamesClient(MainActivity.this, 
GoogleSignIn.getLastSignedInAccount(context));
gamesClient.setViewForPopups(findViewById(R.id.gps_popup));

它给出了 GoogleSignIn.getLastSignedInAccount(this)) 可能为 null 的 lint 警告,所以我只是将其包装在 if 语句 中,列出以下内容:

if(GoogleSignIn.getLastSignedInAccount(this) != null){
GamesClient gamesClient = Games.getGamesClient(MainActivity.this,
GoogleSignIn.getLastSignedInAccount(context));
gamesClient.setViewForPopups(findViewById(R.id.gps_popup));
}

这可能不是一个很好的答案,但它对我有用,所以我希望你能发现它有用,祝你好运。

关于android - 使用 Google Play 游戏获得成就时不会显示弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51556616/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com