How to add gcm messaging to your app
If you tried the gcm playground and it does not work then try gcm quickstart tutorial.
You need to have a google developers account and created an sample empty project using the developers console.
Use the following link to get your configuration file google-services.json
For the package name use: gcm.play.android.samples.com.gcmquickstart
You need to store the Server API Key and Sender ID in a safe location.
Save the google-services.json file into the google-services/android/gcm directory.
Use gradlew assemble to build app
If you use gradle and experience build errors then you might have an older version of gradle installed use instead the gradlew script to get the appropriate version.
gradlew might have problems locating the SDK location make sure to specify ANDROID_HOME
Install the apk located at app/build/outputs/apk
Modify the GcmSender.java file with the API_KEY from previously, file located at gcmsender\src\main\java\gcm\play\android\samples\com\gcmsender use gcmsender to send message
Check your device/emulator for notification or logcat for confirmation of the receipt of the GCM message.
Adding gcm messaging to your app
- Add google dependencies to build.gradle
- Add services to AndroidManifest.xml
- MainActivity initialize broadcast receiver, register broadcast receiver, check google play services, start register service
- Register Intent Service Register with gcm, obtain instanceid, Subscribe to topic
- GCM Listener Service implement onMessageReceived get message from Bundle, show notification
Comments