The Android application to test the GCM notification system.
For testing purposes I slightly changed the code from Android Push Notification using Google Cloud Messaging (GCM) – Part 2, an excellent tutorial how to setup the GCM notification system with an external web server.
The changed code is available on my Github repository.
The Android code is split into 3 classes
- MainActivity – handles the UI and buttons
- GCMBroadCastReceiver – receives the push notifications from the GCM server
- GCMIntentService – handles the received push notifications and displays them as notifications in the top bar of the device
The changes I did to the original code are
- in MainActivity add more buttons to test the unregister function and to list all registered devices
- in MainActivity added handling of the response from the ESP8266 to display error messages
- in GCMIntentService changed the way the received push notifications are shown
- Broadcast sender and receiver to display GCM push notifications on the main UI
When the application is freshly installed and started it shows only a button to register to the GCM service:
When the button is pressed, the device registers itself at the GCM service and sends his registration ID to the ESP8266. There it is stored.
From this moment on the Android device will receive all push notifications that are initiated by the ESP8266 and displays them.
If the button “GET LIST OF REGISTERED DEVICES” is pressed the list is sent from the ESP8266: