Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Android Push Notifications

Author
Message
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 2nd Apr 2013 17:37 Edited at: 9th Apr 2013 01:45
Some people have asked about using Push Notifications on Android, so until the help is updated I'll put the information here for everyone to see. Before we begin you will need a server capable of running PHP scripts for this example to work.

1) Follow the instructions on this page https://developer.android.com/google/gcm/gs.html until you have your API key, ignore the rest.

2) In the Google Play developer console for your app is a section called Services & APIs, in this section you must link your GCM account discovered on the site above with your app.

3) In AGKHelper.java find the function registerPushNotification and replace the number in GCMRegistrar.register() with your project number (not your API key).

4) In your tier 1 code first call PushNotificationSetup(), if it returns 0 then thi platform does not support push notifications. Otherwise wait for GetPushNotificationToken() to return something other than an empty string, if it returns "Error" then something went wrong. Once you have the token you need to send it to your server, you might also want to send some identifying information like a userID so you know who this token belongs to. The code we use looks something like this

We also send the output of GetDeviceName so we know which platform this token belongs to, iOS and Android use different methods.
The server will need to remember the token and who it belongs to so you can send them push notifications later, be aware that the tokens can be 183 characters or more in the case of Android. The device takes no further action after this, it simply sends off its token and the server decides when to send a notification.

5) When you want to send a notification to a device use the attached PHP script to send a message to a particular device token, replacing the $apiKey field with your API key. In our case when a device uploads the result of its turn to the server the server works out which token belongs to the opponent and sends them a notification.

Attachments

Login to view attachments
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 5th Apr 2013 01:32
GREAT THANKS Paul !! sounds really great !!!

Can you stick this post until the help doc is updated ? i will have to use it very soon for my multiplayer competitions
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 8th Apr 2013 11:05
Little silly questions (maybe).

The Device has to send his token only one time to the server (the first time) no ?

is this Token changing when a user uninstall/reinstall the application ?
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 9th Apr 2013 01:43
Quote: "The Device has to send his token only one time to the server"


Correct

Quote: "is this Token changing when a user uninstall/reinstall the application ?"


If the user uninstalls the app they will no longer receive notifications, but if they reinstall it I think they get the same token, I've not tested it.
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 9th Apr 2013 21:12
Thanks Paul

I will test

Login to post a reply

Server time is: 2024-05-01 08:47:51
Your offset time is: 2024-05-01 08:47:51