【问题标题】:Google leaderboard submitscore error:GoogleApiClient must be connected谷歌排行榜提交分数错误:必须连接GoogleApiClient
【发布时间】:2017-10-24 15:39:45
【问题描述】:

在排行榜中保存分数时遇到问题。

在我的情况下,登录屏幕中的第一个是使用谷歌登录的用户。 第二个屏幕是游戏活动,完成游戏后我希望将分数保存在排行榜中。

我正在使用以下代码进行 GoogleApiClient 初始化:-

mGoogleApiClient = new GoogleApiClient.Builder(this)

        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .addApi(Games.API).addScope(Games.SCOPE_GAMES)
        .build();
setContentView(R.layout.activity_game);

用于保存游戏分数:-

 Games.Leaderboards.submitScore(mGoogleApiClient, getResources().getString(R.string.leaderboard_id), millis);

但它是说:- GoogleApiClient 必须连接。

但是当像下面这样向谷歌客户端添加登录 api 时,它表示您不能将 Games.Api 与 Sign_in_api 一起使用。

mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this , this )
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .addApi(Games.API).addScope(Games.SCOPE_GAMES)
            .build();

基本上我的问题是如何在我的第二个活动中连接 GoogleApiClient 以便我可以使用 Games.Leaderboards.submitScore 来保存游戏分数。

我们将不胜感激。

【问题讨论】:

    标签: android google-play-games


    【解决方案1】:

    如果您碰巧使用BaseGameActivity,则不再需要扩展您的活动。而是使用BaseGameUtils 库来解决连接错误并显示对话框。

    尝试通过实现GoogleApiClient.ConnectionCallbacks 和GoogleApiClient.OnConnectionFailedListener 接口来初始化GoogleApiClient。请参阅此documentation 了解更多信息。

    import com.google.android.gms.*;
    import com.google.example.games.basegameutils.BaseGameUtils;
    
    public class MyGameActivity extends Activity implements
            GoogleApiClient.ConnectionCallbacks,
            GoogleApiClient.OnConnectionFailedListener {
    

    如需更多见解,您可能需要检查以下内容:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-24
      • 2016-08-14
      • 1970-01-01
      • 1970-01-01
      • 2018-07-18
      • 1970-01-01
      • 2018-06-26
      相关资源
      最近更新 更多