Dispatching a Mobile Notification
Sending a mobile notification is a great way to engage your users with your app. Depending on your app logic, you may need to send these notifications automatically from your server or in some cases you may need to manually send a mobile notification to your users. This can be done in different approaches. For example you may use the official Firebase console to send mobile notifications. But there are more elegant ways to do this job manually.
On an older post, we had suggested to use “Advanced REST Client Software” to send FCM mobile notifications from your computer but today, we’d like to suggest a new way for doing this. A better way, the postman way!
The Postman way!
Download the postman software first. It will work on Mac and Win. The postman is a very useful software if you are developing an API for your project. It allows you to create API projects and organize them into collections. It’s super handy and full of features. In this post, I will only explain how you can create a new project for sending a simple FCM mobile notification to your app. When you completed that, you may find some time looking more into other features of the software. We’ve been using it for a while and we think you will like it also.
Run the software and on top left of the screen, there’s a big orange “New” button. click it and a window like below will open.
Click on the “Request” option and a new window will open to let you save this request. Request name can be anything, maybe enter “SendFcm”. On the same window, you have the option to create a collection. A collection, is like a folder where you can put all the similar requests in it. You may create a collection and name it “fcm”. Finally click on the orange button at the bottom of the window to save your newly created request. Now, you must be seeing the SendFcm request open in a tab like below.
Prepare the request for sending FCM
The first thing you need to do is to change the request type from “GET” to “POST”. then you should enter the request URL. Copy “https://fcm.googleapis.com/fcm/send” into the field.
Now click on the “Headers” tab and enter the following two Key/Values.
- Key: Content-Type Value: application/json
- Key: Authorization Value: key=your–server–key
Now switch to the “Body” tab and select the “raw” option and copy the following JSON into it.
"title": "Your Title",
"text": "Your Text",
"priority" : "high",
"to" : "/topics/news"
Save your request and click the big blue button which reads “Send”. That’s all. the Postman software now send the FCM request to Google servers and if your app is registered under the “news” topic (as explained in the json message request above), it will receive the FCM message.
The next thing you should do is to read FCM documents to learn more about how you should customize the FCM json message to be able to send FCM messages to your audience.
Enjoy building AIR apps 🙂