【问题标题】:Google Play Game Service - Unlocked Achievement Popup not shownGoogle Play 游戏服务 - 未显示解锁成就弹出窗口
【发布时间】:2015-03-01 04:20:24
【问题描述】:

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

我已经尝试过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


    【解决方案1】:

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

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

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

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

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

    【讨论】:

      【解决方案2】:

      我必须做到以下几点:

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

      【讨论】:

        猜你喜欢
        • 2014-12-15
        • 2014-01-11
        • 2018-05-12
        • 2014-07-08
        • 1970-01-01
        • 2019-01-04
        • 2016-07-14
        • 1970-01-01
        • 2014-12-26
        相关资源
        最近更新 更多