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

Android 调用Games.Acquisitions.unlock时不显示弹出窗口,android,google-play-games,Android,Google Play Games,我目前的Android游戏采用BaseGameActivity 我的游戏使用成就,在需要时解锁 但是,我并不总是看到与解锁事件相关的弹出窗口 我知道只有在您首次解锁成就时才会出现弹出窗口 有些弹出窗口看起来很好,而另一些(来自我游戏中的不同屏幕)从未出现过 我必须做什么才能保证弹出窗口出现 我觉得这与这个警告有关: W/PopupManager(10725): You have not specified a View to use as content view for popups. Fa

我目前的Android游戏采用BaseGameActivity

我的游戏使用成就,在需要时解锁

但是,我并不总是看到与解锁事件相关的弹出窗口

我知道只有在您首次解锁成就时才会出现弹出窗口

有些弹出窗口看起来很好,而另一些(来自我游戏中的不同屏幕)从未出现过

我必须做什么才能保证弹出窗口出现

我觉得这与这个警告有关:

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.
我在活动中调用了
setViewForPopups()
,我的弹出窗口不显示在其中,但是,我从未见过它们


如何调用
setViewForPopups()
,使整个应用程序永远看不到上面显示的警告消息?

通过使用以下代码,我找到了一个解决方案

Games.setViewForPopups(getApiClient(), getWindow().getDecorView().findViewById(android.R.id.content));
我可以让弹出窗口显示。我现在有一个相关的问题。弹出窗口不会显示很长时间

我认为这是因为我有一个自定义动画到这个活动

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

这对我很有效

@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();

}
android.R.id.content为您提供视图的根元素,而无需知道其实际名称/类型/id。请查看游戏。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" />

googleSignInAccount是一个目标

对于在科特林苦苦挣扎的你们来说,这对我来说很有用:

private fun signInSilently() {
    mGoogleSignInClient.silentSignIn().addOnCompleteListener(this)
    { task ->
        if (task.isSuccessful) {
            Log.d(LOG_TAG, "signInSilently(): success")
            mAchievementsClient = Games.getAchievementsClient(this, task.result!!)
            val gamesClient = Games.getGamesClient(this@AchievementsScreen, GoogleSignIn.getLastSignedInAccount(this)!!)
            gamesClient.setViewForPopups(findViewById(android.R.id.content))
            gamesClient.setGravityForPopups(Gravity.TOP or Gravity.CENTER_HORIZONTAL)
        } else {
            Log.d(LOG_TAG, "signInSilently(): failure", task.exception)
            startSignInIntent()
        }
    }
}

最近更新的play服务框架有一些变化。使用此选项,以便您可以看到问候语弹出窗口和解锁弹出窗口

GamesClient gamesClient = Games.getGamesClient(this, GoogleSignIn.getLastSignedInAccount(this));
gamesClient.setViewForPopups(findViewById(android.R.id.content));
gamesClient.setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
不要忘记按要求导入,如-

import android.view.Gravity;
import com.google.android.gms.games.GamesClient;
这非常有效(Kotlin):


你在哪里使用这个代码?我也有同样的警告,但我发现在我的项目中使用这种方法的唯一地方是GPS库的游戏类。我应该在BaseGameActivity中的某个地方手动使用此代码吗?非常感谢。
import android.view.Gravity;
import com.google.android.gms.games.GamesClient;
    Games.getGamesClient(this, googleSignInAccount)
        .setGravityForPopups(Gravity.TOP or Gravity.CENTER_HORIZONTAL)
    val gamesClient = Games.getGamesClient(this@MainActivity, googleSignInAccount)
    gamesClient.setViewForPopups(window.decorView.findViewById(android.R.id.content))