调用Games.Achievements.unlock时不显示弹出窗口

Hec*_*tor 11 android google-play-games

我目前的Android游戏采用了BaseGameActivity.

我的游戏采用了成就,在需要时可以解锁.

但是,我并不总是看到与解锁事件相关的PopUps.

我知道只有在你第一次解锁成就时才会出现弹出窗口.

一些弹出窗口显得很好,其他(从我游戏中的不同屏幕)永远不会出现.

我该怎么做以保证弹出窗口出现?

我有一种感觉它与此警告有关:

W/PopupManager(10725): You have not specified a View to use as content view for popups.

Falling back to the Activity content view which may not work properly in future versions
of the API. 
Use setViewForPopups() to set your content view.
Run Code Online (Sandbox Code Playgroud)

我从我的弹出窗口中没有显示的活动中调用了setViewForPopups(),但我从未见过它们.

如何调用setViewForPopups()以便整个应用程序看到上面显示的WARNING消息?

Hec*_*tor 7

我已经通过使用此代码找到了解决方案

Games.setViewForPopups(getApiClient(), getWindow().getDecorView().findViewById(android.R.id.content));
Run Code Online (Sandbox Code Playgroud)

我可以弹出窗口显示.我现在有一个相关的问题.弹出窗口不会显示很长时间.

我认为这是因为我在此活动中有自定义动画.

有没有办法增加弹出窗口可见的时间?


Saj*_*tta 6

最近更新播放服务框架有一些变化。改用它,这样您就可以看到问候弹出窗口和解锁弹出窗口。

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

不要忘记根据需要导入 -

import android.view.Gravity;
import com.google.android.gms.games.GamesClient;
Run Code Online (Sandbox Code Playgroud)


Phi*_*ert 5

这对我有用。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "onCreate");

    setContentView(R.layout.activity_main);

    // Create the Google API Client with access to Plus, Games and Drive
    // Also set the view for popups
    mGoogleApiClient = new GoogleApiClient.Builder(getApplicationContext())
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
            .addApi(Games.API).addScope(Games.SCOPE_GAMES)
            .addApi(Drive.API).addScope(Drive.SCOPE_APPFOLDER)
            .setViewForPopups(findViewById(android.R.id.content))
            .build();

}
Run Code Online (Sandbox Code Playgroud)

android.R.id.content为您提供视图的根元素,而无需知道其实际名称/类型/ID。看看从当前的活动获得root视图


Mal*_*der 5

Games.setViewForPopups 不推荐使用

要显示弹出窗口,请将下一个代码添加到您的活动或片段布局中:

 <FrameLayout
    android:id="@+id/container_pop_up"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="16dp" />
Run Code Online (Sandbox Code Playgroud)

并将下一个代码添加到您初始化AchievementsClient类对象的代码之后

 GamesClient gamesClient = Games.getGamesClient(MainActivity.this, googleSignInAccount);
 gamesClient.setViewForPopups(findViewById(R.id.container_pop_up));
Run Code Online (Sandbox Code Playgroud)

其中googleSignInAccount是GoogleSignInAccount的对象