I am currently working on an Android app in which I want to use Google Play Games services (Achievements, Leaderboards, ...). After many iterations I finally got the code working to show the Google Play Games Login promt. The problem is now that after the user signs in it takes a while and then throws error code 4 with error message being empty. After doing a lot of research nothing really helped me solving this problem.
I have tried starting it directly out of Android Studio, installing the app manually or over Google Play, all on multiple devices, nothing worked.
Here's some code if required:
private static GoogleSignInClient mGoogleSignInClient;
...
@Override
protected void onCreate(Bundle savedInstanceState) {
...
mGoogleSignInClient = GoogleSignIn.getClient(this, new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN).requestIdToken(getResources().getString(R.string.app_id)).build());
signInSilently(); // Can't be tested yet.
// isSignedIn() and loginDeclined are both false
if(!isSignedIn() && !loginDeclined) startSignInIntent();
}
...
private void startSignInIntent() {
startActivityForResult(mGoogleSignInClient.getSignInIntent(), RC_SIGN_IN);
loginDeclined = true;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
// resultCode = 0
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> task =
GoogleSignIn.getSignedInAccountFromIntent(intent);
try {
GoogleSignInAccount account = task.getResult(ApiException.class);
// Now this never happens :(
System.out.println("SUCCESS!");
} catch (ApiException apiException) {
System.out.println(apiException.getStatusCode() + " + " + apiException.getMessage());
// statusCode is 4, message is "4: "
String message = apiException.getMessage();
if (message == null || message.isEmpty()) {
message = "Error signing in to Google Play Games";
}
new android.app.AlertDialog.Builder(this)
.setMessage(message)
.setNeutralButton(android.R.string.ok, null)
.show();
}
}
}