Google Play游戏服务-未显示解锁成就弹出窗口

问题描述 投票:5回答:2

当我解锁成就时,不会弹出“成就已解锁”弹出窗口,但是成就已解锁,正如我在成就列表中看到的那样。

我已经尝试过this解决方案,但是它不起作用。

我在MainActivity中像这样初始化GoogleApiClient:

 gac = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
            .addApi(Games.API).addScope(Games.SCOPE_GAMES)
            .build();
 app.setGoogleApiClient(gac);
 gac.connect();

在我的“游戏过度活动”中,我执行以下操作:

ApplicationClass app = (ApplicationClass) getApplication();
googleApiClient = app.getGoogleApiClient();

...我会像这样解锁成就:

 Games.Achievements.unlock(googleApiClient, "achievement id");

提前感谢!

android google-play-services google-play-games
2个回答
3
投票

Games API专为单个活动而设计,尽管您可以在多个活动中使用它。您是否有机会查看他们在GithHub pages提供的样本?他们在BasicSamples / libraries / BaseGameUtils下有一些类可能会有所帮助。

您正在使用this在您的主要活动上调用Builder方法。

new GoogleApiClient.Builder(this) //this being your MainActivity

然后您将Api客户端设置为应用程序类。现在,当您使用新的GameOverActivity时,api客户端将尝试显示不再存在于屏幕上的活动的视图。它仅引用您的MainActivity。您不应在Api客户端的Application类上设置变量。这也是一种不好的做法,因为您将监听器回调设置为活动,并且在调用其中一个回调时可能不再存在。

您想与Games API进行交互的任何活动都应源自GitHub BaseGameActivity中的BaseGameUtils。在每个活动中,都有一个名为getApiClient()的方法。


0
投票

我必须执行以下操作:

GamesClient gamesClient = Games.getGamesClient(this, GoogleSignIn.getLastSignedInAccount(this));
gamesClient.setViewForPopups(findViewById(android.R.id.content));
gamesClient.setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
© www.soinside.com 2019 - 2024. All rights reserved.