This wrapper for the Google Play Game Services is a complete rewriting of the wrapper available in a
former thread and is intended to be used with the API 19 or 20 of Google Play Services (the API 21 is still untested).
List of features:
- Sign-in: supported (I even added a GPlayNetworkInfo class to give you more informations about the available networks and their connectivity status);
- Achievements: supported;
- Leaderboards: supported;
- Real-time multiplayer: not supported;
- Turn-based multiplayer: supported;
- Level and XP: supported;
- Gifts and requests: supported;
- Events and quests: not supported;
- Saved games: supported;
- Notifications: supported.
Some features are not supported for the essential and excellent reason that I don't need them.
The library is provided with its Java source code and three B4A modules:
- ClsConnection: manages the sign-in, sign-out and connection events;
- CodConverter: converts your data map to and from the byte array needed for the Saved Games service (this module requires three extra libraries: JSON, ByteConverter and RandomAccessFile);
- CodTurnBasedMatch: helper module for turn-based matches.
Before using this library, you need to:
- download the Google Play services SDK with the Android SDK manager;
- copy the folder "android-sdk\extras\google\google_play_services\libproject\google-play-services_lib\res" to the root of your B4A project (so you should have 3 folders there now: Files, Objets and res);
- copy the library "android-sdk\extras\google\google_play_services\libproject\google-play-services_lib\libs\google-play-services.jar" to your B4A libraries folder;
- add the path to your res folder in the project attributes of your Main module, e.g.:
#AdditionalRes: D:\My Android Projects\My Game\res, com.google.android.gms
- add these lines to your manifest:
AddApplicationText(
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id" />
<meta-data android:name="com.google.android.gms.version"
android:value="@Integer/google_play_services_version" />)
- copy the games-ids.xml file generated by your Google Play developer console in the res/values folder;
- copy this library (Jar+Xml) in your B4A libraries folder.
To generate the games-ids.xml file, click on the link at the bottom of some screens (e.g. achievements) in your developer console (you need of course a game project properly configured to see it):
This file should look like this:
Code:
<?xml version="1.0" encoding="utf-8"?>
<!--
Google Play game services IDs.
Save this file as res/values/games-ids.xml in your project.
-->
<resources>
<string name="app_id">01234567890</string>
<string name="achievement_win_on_a_very_large_map">CgkIuqeG8-kOEAIQAQ</string>
<string name="achievement_win_on_a_large_map">CgkIuqeG8-kOEAIQAg</string>
<string name="achievement_win_on_a_medium_map">CgkIuqeG8-kOEAIQAw</string>
<string name="achievement_win_on_a_small_map">CgkIuqeG8-kOEAIQBA</string>
<string name="achievement_win_on_a_very_small_map">CgkIuqeG8-kOEAIQBQ</string>
<string name="leaderboard_main_score">CgkIuqeG8-kOEAIQBw</string>
</resources>
To set up a game in the Google Play developer console, please read
this, then
this.
To get details about a returned status code, please read
this.