Sign In Register

How can we help you today?

Start a new topic

Android Integration with Google Play signin

Im stuck on how to integrate gamesparks into my libgdx game with google play authentication. Ive gone thru the setup and the authentication tutorials on the gamesparks website.  My onCreate and onStart code looks like this: 

@Override
	protected void onCreate (Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
		config.hideStatusBar = true;
		config.useImmersiveMode = true;

		//Create the client used to sign in to Google services
		mGoogleSignInClient = GoogleSignIn.getClient(this,
				new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
						.requestEmail()
						.build());

		//Gamesparks stuff
		GSAndroidPlatform.initialise(this, "Y350111e9EVD", "onfWeN5kCAuB4sgljZvz2ck34tJJsFu9", "device", false, true);

		game = new RoboSmash(this);

		initialize(game, config);

	}
@Override
	protected void onStart() {
		super.onStart();
		GSAndroidPlatform.gs().start();
	}

  When the game is initialized a call to log in via google play game services is called.  That code looks like this when it connects:

private void onConnected(final GoogleSignInAccount googleSignInAccount) {
		Log.d(TAG, "onConnected(): connected to Google APIs");

		GamesClient gamesClient = Games.getGamesClient(AndroidLauncher.this, googleSignInAccount);
		gamesClient.setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
		gamesClient.setViewForPopups(((AndroidGraphics) Gdx.graphics).getView());

		mPlayersClient = Games.getPlayersClient(this, googleSignInAccount);

		// Set the greeting appropriately on main menu
		mPlayersClient.getCurrentPlayer()
				.addOnCompleteListener(new OnCompleteListener<Player>() {
					@Override
					public void onComplete(@NonNull Task<Player> task) {
						String displayName;
						if (task.isSuccessful()) {
							user = new User();
							user.setDisplayName(task.getResult().getDisplayName());
							user.setPlayerID(task.getResult().getPlayerId());
							game.user = user;
							game.updateUserInfo();
							GSAndroidPlatform.gs().getRequestBuilder().createGooglePlayConnectRequest()
									.setAccessToken(googleSignInAccount.getIdToken()).send(new GSEventConsumer<GSResponseBuilder.AuthenticationResponse>() {
								@Override
								public void onEvent(AuthenticationResponse authenticationResponse) {
									Log.d("GameSparks", "New Player:" + authenticationResponse.getNewPlayer());
								}
							});
						} else {
							Exception e = task.getException();
							handleException(e, getString(R.string.players_exception));
							displayName = "???";
						}
					}
				});
	}

 This runs but starts up like this and have to hit the back button to proceed to my game.

image


Is this normal behavior and if so I want it to create a new player if player doesnt exist

Login to post a comment