我刚刚将 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/