2014-10-20 126 views
5

谷歌玩游戏成就解锁弹出我用这个简单的方法,从开发文档解锁成就:没有显示

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

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

回答

9

我一直在努力,这就是为什么决定分享它在计算器上。我已在my developer's blog上描述了对此问题的简单修复。

这里是短版:

只是一个视图添加到您想要显示的成就在这样的布局:

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

当你有你的布局准备好你NEET里面执行这个你活动或片段:

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

您必须确定您的GoogleApiClient已连接,否则您的应用程序将崩溃。

+1

是否必须连接GoogleApiClient?如果它已正确实例化但未实际连接?我不明白为什么连接应该对设置视图有任何影响。 – Tosen 2015-04-21 13:05:54

+0

完美工作.. – 2016-08-04 18:51:41

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

这是亚切克Kwiecień答案相同

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

这改变了,因为有两个参数setViewForPopups已经过时了。