Initializing Games Client in Android

Initializing Games Client in Android

I had the same problem initially. What I had to do was look at the full, unfiltered LogCat log. There, I saw the message:

GamesIntentService(17929): Using Google Play games services requires a metadata tag with the name "com.google.android.gms.games.APP_ID" in the application tag of your manifest

So, assuming you created an entry in your strings.xml called app_id, try adding the following to your AndroidManifest.xml under the <application> tag:

<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id" />

You can find your APP_ID in the Games Services tab

**Games Services** tab

What are some methods of initializing server-client connections to an android client device?

Google Cloud Messaging GCM. It's free. It's unlimited. It's maintained by Google. And it's already installed on user's phones.

That being said, the ideal way now is to use Google Play Services and have people login with their Google+ accounts. Watch the last Google I/O 2013 session on Google Play Services. The demo went wrong during the general keynote, but it works fine otherwise.

Google Play Services takes care of all the networking issues for you (and also falls back to local wifi if users are on the same network). The price you have to pay is that you must force your users to use Google+ if they want that multiplayer functionality.

Submitting GPGS events from server

What you want to do is informally called hybrid authorization, and the best way to do that is to send an Authorization Code from the Android app to your web server. The web server can then exchange the code (one time) for an Access Token and a Refresh Token. This is not specific to games and is something that many apps using Sign-In with Google do all the time.

The Google+ Haiku+ Sample shows and example of this flow. The specific pieces you may want to look at (in the Android app) are MainActivity.codeSignInRequired(), the private class in MainActivity called CheckOrRetrieveCodeTask, and HaikuSession.getCodeSynchronous() which calls the GoogleAuthUtil.getToken() method to get the one-time code.

Note that getting this code requires your user to see and accept the standard Google SignIn consent dialog. Additionally, once you use the code once it is invalid (for security reasons) so make sure that your server saves the tokens that it gets from exchanging the code.

The Haiku+ Java Server has a good example of how to exchange the authorization code for tokens.

Once you have the access token, you can call any Google APIs to which the user consented on the client. The Haiku+ Java Server shows an example of this when it fetches the users circles.

Yes, this is a complicated flow but it is the best and most secure way to do this. If you don't want to do all of this, I'd recommend submitting Events from the client. The Google Play Games SDK for Android makes this very easy and automatically handles all of the caching and retry logic.



Related Topics



Leave a reply



Submit