I'm trying to use the Google Games turn based Api for my Android game. The code I use to connect my GoogleApiClient
comes from Google's Api samples or documentation.
Inside of my implementation of onConnectionFailed
I have tried two separate approaches:
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;
}
}
The first approach above comes from the TBMP Skeleton sample. This results in a dialog being created with the message
Failed to sign in. Please check your network connection and try again.
and the connection is never made.
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();
}
}
In the second approach it ends up calling startResolutionForResult
which passes RESULT_SIGN_IN_FAILED
to onActivityResult. From the documentation
Result code sent back to the calling Activity when signing in fails.
The attempt to sign in to the Games service failed. For example, this might happen if the network is flaky, or the user's account has been disabled, or consent could not be obtained.
This puzzles me since I have no problems getting the sign in flow to work in a sample. However, in my game I am never prompted to select a Google account before the sign in fails.
For the record I've tried all the steps here https://developers.google.com/games/services/android/troubleshooting and it still fails.
How can I resolve this error in order to sign in?
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();
}
for further reference, please check the link link