GCM Notification using Rest client

Abhishek ujjain
AndroidPub
Published in
2 min readMar 20, 2017

I will explain simple steps which will help lots of developer working on notification part of android and spends lots of time to finding appropriate and optimized way to implement.Honestly there are lots of third party are available which can trigger notification for you.

But there is catch what if the key which used for triggering notification is production key.You may end up screw whole user experience.Reason is simple as there is chance that if you use console provided by any third party you might end up sending notification to production app.

Rest client gives you controlled environment to test and trigger notification.

Steps:

1.Download latest GCM sample which has provided nicest way to implement cloud messaging for beginners.

2.You have to download “R.string.gcm_defaultSenderId” which can be downloaded from

Here you have follow below mentioned steps to add firebase:

To add Firebase to your app you’ll need a Firebase project and a Firebase configuration file for your app.

a. Create a Firebase project in the Firebase console, if you don’t already have one. If you already have an existing Google project associated with your mobile app, click Import Google Project. Otherwise, click Create New Project.

b. Click Add Firebase to your Android app and follow the setup steps. If you’re importing an existing Google project, this may happen automatically and you can just download the config file.

c. When prompted, enter your app’s package name. It’s important to enter the package name your app is using; this can only be set when you add an app to your Firebase project.

d. At the end, you’ll download a google-services.json file. You can download this file again at any time.

e. If you haven’t done so already, copy this into your project’s module folder, typically app/.

3.Now we are ready to trigger cloud based notification. Instead of using any platform for triggering notification ,you can set up this on any REST client with POST call to “https://gcm-http.googleapis.com/gcm/send” and headers

Content-Type:application/json
Authorization:key=AIzaSyZ-1u…0GBYzPu7Udno5aA

for sending message to any topic :

{
"to": "/topics/news",
"data": {
"message": "Your latest news!",
}
}

for sending message to particular device(using device token):

{
"to": "YOUR_DEVICE_TOKEN",
"data": {
"message": "This is a GCM Topic Message!",
}
}

Happy coding. :)

--

--