java - Google Play 游戏服务 BaseGameUtils 中没有 getApiClient()

标签 java android google-play-services google-play-games

我刚刚将 google play services 排行榜添加到我的游戏中,但存在一些问题。我无法开始排行榜 Activity 。这是我的代码

startActivityForResult(Games.Leaderboards.getLeaderboardIntent(getApiClient(), "leaderboard_id"), 5000);

问题是没有任何 getApiClient() 方法。有什么想法吗?

最佳答案

您必须使用 GoogleApiClient 类型的对象。你的代码应该是这样的:

public class MainActivity extends Activity implements GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener{
        GoogleApiClient mGoogleClient;
        ...

        @Override
        protected void onCreate(final Bundle savedInstanceState) {
            ...
            //Google Game 
            mGoogleClient = new GoogleApiClient.Builder(this, this, this)
           .addApi(Games.API)
           .addScope(Games.SCOPE_GAMES)
           .setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL)
           .build();

        }

        @Override
        public void onStart(){
            super.onStart();
            //Here is a good place to connect with Google Api
            mGoogleClient.connect();
        }

        @Override
        public void onConnected(Bundle connectionHint) {}

        @Override
        public void onConnectionSuspended(int cause) {}

        @Override
        public void onConnectionFailed(ConnectionResult connectionResult) {}

}

关于java - Google Play 游戏服务 BaseGameUtils 中没有 getApiClient(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21798257/

相关文章:

java - Android Studio 0.1.1 gradle 项目中的 Google Play 服务?

java - (Node.js/Java) 如何使 XML 输出漂亮

android - 如何通过 BroadcastReceiver 将应用程序从后台带到前台

android - Cordova 错误ENOENT

Android canvas 绘制由多个简单形状定义的复杂形状

android - Android Instant 应用程序中的 FirebaseApp 初始化失败

android - GoogleApiClient 连接失败,状态码为 SIGN_IN_REQUIRED

java - 为什么 getClass() 不能作为静态方法使用?

java - while (var != var)

java - 什么是 Java 中用于文本字符串的好的 64 位散列函数?