[英]About Google Play Games Services on Android Studio
我试图在我的项目中添加排行榜和成就系统大约3天...
我可以登录我的应用程序,但是当我尝试打开排行榜时,它说:
E/UncaughtException: java.lang.IllegalStateException: GoogleApiClient is not configured to use the Games Api. Pass Games.API into GoogleApiClient.Builder#addApi() to use this feature.
at com.google.android.gms.common.internal.zzac.zza(Unknown Source)
at com.google.android.gms.games.Games.zzc(Unknown Source)
at com.google.android.gms.games.Games.zzb(Unknown Source)
at com.google.android.gms.games.Games.zzi(Unknown Source)
at com.google.android.gms.games.internal.api.LeaderboardsImpl.getLeaderboardIntent(Unknown Source)
at com.google.android.gms.games.internal.api.LeaderboardsImpl.getLeaderboardIntent(Unknown Source)
at com.google.android.gms.games.internal.api.LeaderboardsImpl.getLeaderboardIntent(Unknown Source)
at tr.com.blogspot.etkinlikhavuzu.benimilkogretmenim.Ilksayfa.onClick(Ilksayfa.java:309)
at android.view.View.performClick(View.java:5702)
at android.widget.TextView.performClick(TextView.java:10888)
at android.view.View$PerformClick.run(View.java:22541)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
我怎么解决这个问题?
我写了这段代码:
case R.id.Enbasarili:
startActivityForResult(Games.Leaderboards.getLeaderboardIntent(mGoogleApiClient,
getResources().getString(R.string.leaderboard_en_cok_70_ve_ustu_basari_gosterenler)), RC_UNUSED);
break;
谢谢你的帮助...
尝试检查这些文档- 访问Android游戏中的Play游戏服务API,并开始使用Android的Play游戏服务
获取Google Api客户端并进行连接
您的游戏必须具有对
GoogleApiClient
对象的引用,才能对Google Play游戏服务进行任何API调用。 使用GoogleApiClient.Builder
类在onCreate()
创建GoogleApiClient
对象。 例如:
private GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create the Google Api Client with access to the Play Games services
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
// add other APIs and scopes here as needed
.build();
// ...
}
为了使您的游戏与Google Play游戏服务进行通信,您的客户端必须首先建立连接。 一旦您的游戏不再需要访问这些服务,就可以断开客户端的连接。
为了使用Google Play游戏服务,您的游戏需要实现用户登录,才能通过Google Play游戏服务验证玩家的身份。 如果用户未通过身份验证,则在调用Google Play游戏服务API时,您的游戏将遇到错误。
private static int RC_SIGN_IN = 9001;
private boolean mResolvingConnectionFailure = false;
private boolean mAutoStartSignInflow = true;
private boolean mSignInClicked = false;
// ...
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
if (mResolvingConnectionFailure) {
// Already resolving
return;
}
// If the sign in button was clicked or if auto sign-in is enabled,
// launch the sign-in flow
if (mSignInClicked || mAutoStartSignInFlow) {
mAutoStartSignInFlow = false;
mSignInClicked = false;
mResolvingConnectionFailure = true;
// Attempt to resolve the connection failure using BaseGameUtils.
// The R.string.signin_other_error value should reference a generic
// error string in your strings.xml file, such as "There was
// an issue with sign in, please try again later."
if (!BaseGameUtils.resolveConnectionFailure(this,
mGoogleApiClient, connectionResult,
RC_SIGN_IN, getString(R.string.signin_other_error))) {
mResolvingConnectionFailure = false;
}
}
// Put code here to display the sign-in button
}
请参阅示例以更好地了解Google Play游戏的代码实现。
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.