Google Play Games achievement unlocked popup not showing

寵の児 提交于 2019-11-26 21:23:51

问题


I'm unlocking achievement using this simple method from developers docs:

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

Achievement unlocks, but no popup shows up. There is also no popup when logged in to Google Play Games - which is connected.


回答1:


I was struggling with this for a while, that's why decided to share it on stackoverflow. I've described a simple fix to this problem on my developer's blog.

Here is the short version:

Just add a view to the layouts you want to display achievements on like this:

<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" />

When you have your layout ready you neet to execute this inside your Activity or Fragment:

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

You have to be sure, that your GoogleApiClient is connected though, otherwise your app will crash.




回答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" />

This is the same in Jacek Kwiecień answer

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

This changed because setViewForPopups with 2 parameters is deprecated.



来源:https://stackoverflow.com/questions/26474718/google-play-games-achievement-unlocked-popup-not-showing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!