Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Play Games achievement unlocked popup not showing

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.

like image 813
Jacek Kwiecień Avatar asked Oct 20 '14 20:10

Jacek Kwiecień


People also ask

How do I see my achievements on Google Play Games?

To create an achievement for a new and unpublished game, go to the Google Play Console entry for your game under the Games with Game Services tab. Select the Achievements tab on the left, and click the Add Achievement button. Then, simply fill out the information required for this achievement.


2 Answers

Jacek and user3782779 answers didn't work for me, I had to do the following:

GamesClient gamesClient = Games.getGamesClient(this, GoogleSignIn.getLastSignedInAccount(this));
gamesClient.setViewForPopups(findViewById(android.R.id.content));
gamesClient.setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
like image 188
thiagolr Avatar answered Sep 16 '22 18:09

thiagolr


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.

like image 40
Jacek Kwiecień Avatar answered Sep 17 '22 18:09

Jacek Kwiecień