[Android Apps and Games] itspheres:
The article was written in the course of the game's development CLEAR SKY 2

The first part here!

Code

In the main Activity implement two interfaces GameHelperListener, ActionResolver:

public class MainActivity extends AndroidApplication implements GameHelperListener, ActionResolver

GameHelperListener interface is as follows:

public interface GameHelperListener {
/ **
* Called when an attempt to login. This method can show
* User button «Sign-in» for manual entry
* /
void onSignInFailed ();

/ ** Called when a successful login attempt * /
void onSignInSucceeded ();
}

Interface ActionResolver create ourselves. He needed to call the platform-dependent code. This technique is described in the official wiki libgdx. An example of the interface:

public interface ActionResolver {
/ ** Check the status of the user input * /
public boolean getSignedInGPGS ();

/ ** Log * /
public void loginGPGS ();

/ ** Send the result in the high score table * /
public void submitScoreGPGS (int score);

/ **
* Unlock achievement
*
*param AchievementId
* ID achievements. Taken from the file games-ids.xml
* /
public void unlockAchievementGPGS (String achievementId);

/ ** Show Activity records to the table * /
public void getLeaderboardGPGS ();

/ ** Show Activity achievements * /
public void getAchievementsGPGS ();

}

Example code main Activity:

public class MainActivity extends AndroidApplication implements
GameHelperListener, ActionResolver {
// Assistant to work with gaming services
private GameHelper gameHelper;
// Class of our games
private TestGame game;

Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
// CLIENT_ALL instruct you on the use of the API all customers
gameHelper = new GameHelper (this, GameHelper.CLIENT_ALL);
// Disable automatic login when starting the game
gameHelper.setConnectOnStart (false);
gameHelper.enableDebugLog (true);
// From turning off the screen without the use of additional
// Permits (less than permissions - more confidence in the application)
getWindow (). addFlags (WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
// Input parameter this is ActionResolver. Allows you to call from
// Game loop platform-specific methods GPGS
game = new TestGame (this);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration ();
initialize (game, config);
gameHelper.setup (this);

}

// Methods gameHelper'a: onStart (), onStop () are called to work correctly
// GPGS in the lifecycle of android-app

Override
protected void onStart () {
super.onStart ();
gameHelper.onStart (this);
}

Override
protected void onStop () {
super.onStop ();
gameHelper.onStop ();
}

Override
protected void onDestroy () {
super.onDestroy ();

}

Override
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
super.onActivityResult (requestCode, resultCode, data);
// Here gameHelper decides to connect, or reconnect
// Disconnected from the game services, depending on the result code
// Activity
gameHelper.onActivityResult (requestCode, resultCode, data);
}

Override
public boolean getSignedInGPGS () {
// Connection status
return gameHelper.isSignedIn ();
}

Override
public void loginGPGS () {
try {
runOnUiThread (new Runnable () {

Override
public void run () {
// Initiate user entry. Can be called a dialogue
// Login. Performed in UI-stream
gameHelper.beginUserInitiatedSignIn ();

}
});
} Catch (Exception e) {
e.printStackTrace ();
}

}

Override
public void submitScoreGPGS (int score) {
// Send game points to a specific table records with ID
// "HgkIr62KmoQJEAIQAQ"
Games.Leaderboards.submitScore (gameHelper.getApiClient (),
"HgkIr62KmoQJEAIQAQ", score);

}

Override
public void unlockAchievementGPGS (String achievementId) {
// Open achievement with ID achievementId
Games.Achievements.unlock (gameHelper.getApiClient (), achievementId);

}

Override
public void getLeaderboardGPGS () {
Activity // call for all registered tables records. as
Activity // can call for a specific table
startActivityForResult (
Games.Leaderboards.getAllLeaderboardsIntent (gameHelper
.getApiClient ()), 100);

}

Override
public void getAchievementsGPGS () {
// Call Activity achievements
startActivityForResult (
Games.Achievements.getAchievementsIntent (gameHelper
.getApiClient ()), 101);

}

Override
public void onSignInSucceeded () {
}

Override
public void onSignInFailed () {
}

}

Suppose we have in the game provided the achievement - to collect 1 million. Player points, the code implementing it would look like this:

public static void checkTotalPoints (int points) {
ActionResolver res = getActionResolver ();
if (! res.getSignedInGPGS ()) {
return;
}
if (points> = 1000000) {
res.unlockAchievementGPGS ("HgkIr62KmoQJEAIQGA");
}

}

Same thing with a table of records, only even easier: you just need to call the submitScoreGPGS (int score) interface ActionResolver.

PS To test gaming services need to export apk-file with the same certificate as in the developer console. Just need to add accounts testers in the console. Changes in gaming services come into effect after a while.

Google Play Clear Sky 2