I would like to know if there is an account available on an Android device which is registered as a Google Play Games account.
I am using Java, and LibGDX.
Any ideas?
I would like to know if there is an account available on an Android device which is registered as a Google Play Games account.
I am using Java, and LibGDX.
Any ideas?
Edit: Google Play Games no longer needs a Google+ account as mentioned here
Issue: Asking for unnecessary scopes
// Don’t do it this way!
GoogleApiClient gac = new GoogleApiClient.Builder(this, this, this)
.addApi(Games.API)
.addScope(Plus.SCOPE_PLUS_LOGIN) // The bad part
.build();
// Don’t do it this way!
In this case, the developer is specifically requesting the plus.login scope. If you ask for plus.login, your users will get a consent dialog.
Solution: Ask only for the scopes you need
// This way you won’t get a consent screen
GoogleApiClient gac = new GoogleApiClient.Builder(this, this, this)
.addApi(Games.API)
.build();
// This way you won’t get a consent screen
Remove any unneeded scopes from your GoogleApiClient construction along with any APIs you no longer use.
Original answer:
A Google Play Games account is available when the user is signed in with a Google+ account as mentioned here and here, and that by itself is available if the user is signed in with a Google account, so our first approach would be:
To check if the Android device has a Google user logged-in:
public boolean isLoggedInGoogle() {
AccountManager manager = (AccountManager) getSystemService(ACCOUNT_SERVICE);
Account[] list = manager.getAccounts();
for (Account account : list) {
if (account.type.equalsIgnoreCase("com.google")) {
return true;
}
}
return false;
}
Now, to check if the Android device has a Google+ user logged-in.
You can try to start a login sequence with a Google API client, as mentioned in this question:
private GoogleApiClient buildGoogleApiClient() {
return new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API, null)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
}
You can also just make use of the BaseGameUtils of the Play Games Services APIs. There are a few samples of how to achieve it in this link.