【问题标题】:Google Play Games achievement unlocked popup not showingGoogle Play 游戏成就解锁弹窗未显示
【发布时间】:2014-12-15 23:17:50
【问题描述】:

我正在使用开发者文档中的这种简单方法解锁成就:

Games.Achievements.unlock(getApiClient(), "my_achievement_id");

成就解锁,但没有弹出窗口出现。登录到已连接的 Google Play 游戏时也没有弹出窗口。

【问题讨论】:

    标签: android google-play-services google-play-games


    【解决方案1】:

    只需将视图添加到要显示成就的布局中,如下所示:

    <FrameLayout
            android:id="@+id/gps_popup"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="20dp" />
    

    当您准备好布局后,您需要在 Activity 或 Fragment 中执行此操作:

    Games.setViewForPopups(getApiClient(), findViewById(R.id.gps_popup));
    

    您必须确保您的 GoogleApiClient 已连接,否则您的应用会崩溃。

    【讨论】:

    • GoogleApiClient 真的必须连接吗?如果它被正确实例化但没有实际连接怎么办?我不明白为什么连接会对设置视图产生任何影响。
    • 指向您博客文章的链接似乎已损坏。
    【解决方案2】:
    <FrameLayout
            android:id="@+id/gps_popup"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="20dp" />
    

    这在 Jacek Kwiecień 的回答中是一样的

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

    这发生了变化,因为带有 2 个参数的 setViewForPopups 已被弃用。

    【讨论】:

      【解决方案3】:

      Jacek 和 user3782779 的答案对我不起作用,我必须执行以下操作:

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

      【讨论】:

        【解决方案4】:

        遇到了同样的问题。我通过在成就中添加图标解决了这个问题。我不是在开玩笑,这真的很奇怪,但在那之后它开始起作用了。请注意,我说的是未发布项目,我只是在测试我的应用程序并想知道发生了什么。

        【讨论】:

          【解决方案5】:

          唯一适用于我有多项活动的view 是:

          activity.window.decorView.findViewById(android.R.id.content)
          

          我在成就弹出窗口中遇到了同样的问题。仅使用我自己的视图即可正确显示“欢迎回来”弹出窗口,但是一旦我开始打开其他屏幕,我想在其中显示成就解锁弹出窗口,它就无法正常工作。唯一有效的方法是使用 decorView 中的 content 视图

          val gamesClient = Games.getGamesClient(activity, googleSignInAccount)
          gamesClient.setGravityForPopups(Gravity.TOP or Gravity.CENTER_HORIZONTAL)
          gamesClient.setViewForPopups(activity.window.decorView.findViewById(android.R.id.content))
          

          您可以从您打开的任何新活动中调用此代码,一旦您解锁成就,弹出窗口就会显示在那里。

          【讨论】:

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