谷歌游戏服务 - 成就解锁弹窗未显示

7
当我解锁一个成就时,“成就解锁”弹出窗口没有弹出,但是我可以在成就列表中看到该成就已解锁。
我已经尝试了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");

提前感谢!

2个回答

4

游戏API是为单个Activity设计的,尽管您可以在多个Activity中使用它。您有没有机会查看他们在GithHub页面提供的示例?他们在BasicSamples/libraries/BaseGameUtils下有一些类可能会有所帮助。

您正在主Activity上使用Builder方法调用this

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

然后,您正在将Api客户端设置为应用程序类。现在,当您处于新的 GameOverActivity 时,api客户端尝试在不再出现在屏幕上的活动上显示视图。它只有对MainActivity的引用。您不应该为Api Client在Application类上设置变量。这也是不好的做法,因为您将侦听器回调设置为活动,并且可能在回调之一被调用时不再存在。

您想要与游戏API交互的任何活动都应派生自 BaseGameActivity ,可以在GitHub上找到 BaseGameUtils 。在每个活动中,您都将拥有一个名为 getApiClient() 的方法。


3

我必须执行以下操作:

GamesClient gamesClient = Games.getGamesClient(this, GoogleSignIn.getLastSignedInAccount(this));
gamesClient.setViewForPopups(findViewById(android.R.id.content));
gamesClient.setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接