BLU*_*LUC 14 java android google-api-client google-play-games
我正试图在我的Android游戏中使用Google Games回合制Api.我用来连接我的代码GoogleApiClient来自Google的Api示例或文档.
在我的实现中,onConnectionFailed我尝试了两种不同的方法:
if (signInClicked || autoStartSignInFlow) {
autoStartSignInFlow = false;
signInClicked = false;
resolvingConnectionFailure = 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,
apiClient, connectionResult,
RC_SIGN_IN, R.string.signin_other_error)) {
resolvingConnectionFailure = false;
}
}
Run Code Online (Sandbox Code Playgroud)
上面的第一种方法来自TBMP Skeleton样本.这会导致使用消息创建对话框
登录失败.请检查您的网络连接,然后重试.
并且永远不会建立联系.
if (connectionResult.hasResolution()) {
// https://developers.google.com/android/guides/api-client under 'Handle connection
// failures'. I don't know if this is solving the problem but it doesn't lead to
// 'please check your network connection' message.
try {
if(LoggerConfig.ON) {
Log.e(TAG, "onConnectionFailure, attempting to startResolutionForResult.");
}
resolvingConnectionFailure = true;
connectionResult.startResolutionForResult(this, REQUEST_RESOLVE_ERROR);
} catch (IntentSender.SendIntentException e) {
// There was an error with the resolution intent. Try again.
if(LoggerConfig.ON) {
Log.e(TAG, "onConnectionFailure, there was an error with resolution intent");
}
apiClient.connect();
}
}
Run Code Online (Sandbox Code Playgroud)
在第二种方法中,它最终调用startResolutionForResult传递RESULT_SIGN_IN_FAILED给onActivityResult.从文档中
登录时发送回调用活动的结果代码失败.
登录游戏服务的尝试失败.例如,如果网络不稳定,或者用户的帐户已被禁用或无法获得同意,则可能会发生这种情况.
这让我感到困惑,因为我没有问题让流程符号在样本中工作.但是,在我的游戏中,在登录失败之前,我从未被提示选择Google帐户.
为了记录,我已尝试了https://developers.google.com/games/services/android/troubleshooting的所有步骤,但仍然失败.
如何解决此错误才能登录?
小智 3
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();
// ...
}
@Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
@Override
protected void onStop() {
super.onStop();
mGoogleApiClient.disconnect();
}
Run Code Online (Sandbox Code Playgroud)
如需进一步参考,请检查链接 链接
| 归档时间: |
|
| 查看次数: |
752 次 |
| 最近记录: |