(How to implement GCM in your code is very well explained in the official tutorial here).
Our test page will help us easily send GCM messages to a registered device, that way mimicking a server behaviour with very little effort (and without the need to ask the server guy "ok - now try to send a message")
Our test page for sending messages |
Installation steps:
- If you haven't done it so far - start of with the "getting started" guide.
- In the Google developer console --> API's & Auth --> Credentials --> Create a new key:
- Select "key for browser applications"
- Leave the text box emtpy (that will allow all referrers! make sure to use it only in debug)
- The final result will look something like:
- From the device in which you want to receive the message - extract the `registration ID`. The easiest way is to set a log message once the registration is received, or, via the shared preferences after you had it saved.
- Preparing the web page tester -
- Make sure you have a folder that can run PHP scripts
- Download the source code for the test page.
- Open the 'http://localhost/..../gcm_demo.html" and you're good to go!
Running step:
This is actually the fun part - paste all the data you collected into the web page and hit submit. Witness the message arriving to your device (or witness the error code and fix it :))
Pay attention that GCM as a service doesn't guarantee that the message will arrive, or when it will arrive. Besides building your app structure around this knowledge, you might experience it during your testing.
No comments:
Post a Comment