I've a problem. I'm making a game with LibGDX. Now I want to implement Google Sign-In. I searched everywhere, but can't find anything.
What I need is a Resolver to abstract code for specific platform, but I don't know how to do it. Can someone help?
EDIT
Here's the code, this is my Android Resolver:
public GoogleResolverAndroid(final Context context) {
handler = new Handler();
this.context = context;
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this.context)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
@Override
public void loginGoogle() {
signIn();
}
@Override
public boolean getIsLoggedInGoogle() {
return isLoggedIn;
}
public void signIn() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
((AndroidLauncher)context).startActivityForResult(signInIntent, RC_SIGN_IN);
mGoogleApiClient.connect();
}
private void signOut() {
Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
isLoggedIn = false;
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
}
if (requestCode == REQUEST_RESOLVE_ERROR) {
mResolvingError = false;
if (resultCode == RESULT_OK) {
// Make sure the app is not already connected or attempting to connect
if (!mGoogleApiClient.isConnecting() &&
!mGoogleApiClient.isConnected()) {
mGoogleApiClient.connect();
}
}
}
}
//some code other code
//
//
//
@Override
public void onConnected(@Nullable Bundle bundle) {
OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
if (opr.isDone())
{
Gdx.app.debug(TAG, "Loggato");
GoogleSignInResult result = opr.get();
handleSignInResult(result);
} else {
opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
@Override
public void onResult(GoogleSignInResult googleSignInResult) {
handleSignInResult(googleSignInResult);
}
});
}
}
@Override
public void onConnectionSuspended(int i) {
Gdx.app.debug(TAG, "onConnectionSuspended ma non so perchè");
}
and this is my class that call the resolver method in libgdx
// Google
googleLoginButton = new LoginButton(tbs, stage, main);
googleLoginButton.setPosition(stage.getViewport().getWorldWidth()/2-googleLoginButton.getWidth() - 10,
stage.getViewport().getWorldHeight()/2-googleLoginButton.getHeight()/2 - 200);
googleLoginButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
main.googleResolver.loginGoogle();
googlePrefs = main.googleResolver.getGooglePrefs();
gLoginIn = true;
Gdx.app.debug(TAG, googlePrefs.toString());
}
});
The way I solved this for my game was with the use of Interfacing. So you have to write Android and iOS specific code that use this interfaces from your core game.