Before you try to send FCM messages, you should first learn the difference between them. Generally, there are two kinds of FCM messages, the Notification and Data messages. If you are trying the Firebase console to send FCM messages, it only supports Notification messages. (At least for the moment of when I am writing this post. They may upgrade their console in future).
Notification messages will generate a notification in your device status bar while the Data messages will let you send key/value pairs of data to your app and no visual notification will be generated when using them. The Firebase console however lets you send mix messages meaning that you can send pairs of key/value data along with your notification message. These kind of messages are officially considered as Notification messages.
Heads up! If you are reading this and you are NOT an Adobe AIR developer, you will still benefit from reading this post. Go to the “How to use Advanced REST API Client Software to Send FCM Messages” section and start reading from there.
While we were developing the FCM ANE, we decided to consider the mix ones as the third type of FCM messages! The reason is that we have customized how the ANE works for best practices.
Overall, when working with the FCM ANE, you should think that you can send three types of messages to devices, Notification, Data and Mixed messages. When a device receives these messages, depending on the current status of your app on the device, the ANE will behave differently. To learn about these differences, you should read this page of our WIKI guide which will make you completely familiar with how you should treat the incoming messages.
Now that you know what kind of messages you can receive, it’s time to start developing your application with the FCM ANE.
How to use Advanced REST Client Software to Send FCM Messages
In real life scenarios, you will need a web server to send Data messages, or you may use the official Firebase Console to send Notification messages but when developing your app, you will need an easy workaround to send different kind of FCM messages. So it will speed up your development process. For this reason, you can build your own REST Client software OR simply use the Google Chrome app called the Advanced REST Client.
To install this small but helpful app, you should open this link in your Chrome browser. Data on that page will help you install the app in a few seconds. When installed, launch the app and you will see something like below.
To be able to send FCM messages, you need to connect to Google’s FCM endpoint address, so put “https://fcm.googleapis.com/fcm/send” into the Request URL field. The second thing you should remember is that you must send your request via POST. Therefore, chose the POST option. Next to the POST option, there is a dropdown menu (Custom content type), open it and select the “application/json” option.
Below those, you should enter your header request information. To do that, make sure the tab Raw Headers is selected and enter the following information:
Hint! You can find your server key in the Firebase console: Your project, settings, Project settings, Cloud messaging, Server Key.
You’re almost there. Now you should enter the data you wish to send. To do that, make sure the Raw payload tab is selected and enter the kind of FCM message you wish to send.
If you want to learn how you should customize the information you are sending, your best source is the official Firebase documentation. In this page, it is explained in details that what does each parameter mean and how you can use them to customize your messages.
Notice! When sending a mixed message, to be able to receive the key/value data in your app, you have to include the “click_action”: “MY_INTENT” parameter as shown above. If you are an AIR developer, setting this parameter is all you need to receive the key/value data and everything else will be taken care for you automatically inside the ANE. However, if you are using other platforms than AIR, you need to build your own activity on the Android side and manually catch the incoming variables. Considering that this post is mainly used by AIR developers, we will not talk about how you can do things in other platforms but I’m sure you can find your way around by some Googling.
The good thing about the Advanced REST Client software is that it allows you to save your work! For instance, we are used to save three different requests, one for simple notifications, another one for Data messages and finally the third one for the Mixed messages. This way, we can easily switch between different types and send FCM messages quickly.
I’m sure you will find this trick very helpful when you are developing your application. After you made sure that everything related to FCM is working as expected, you may move your code to your own server.
How to send FCM messages from my server
Send FCM Messages like a pro!
Before you try to send FCM messages, you should first learn the difference between them. Generally, there are two kinds of FCM messages, the Notification and Data messages. If you are trying the Firebase console to send FCM messages, it only supports Notification messages. (At least for the moment of when I am writing this post. They may upgrade their console in future).
Notification messages will generate a notification in your device status bar while the Data messages will let you send key/value pairs of data to your app and no visual notification will be generated when using them. The Firebase console however lets you send mix messages meaning that you can send pairs of key/value data along with your notification message. These kind of messages are officially considered as Notification messages.
While we were developing the FCM ANE, we decided to consider the mix ones as the third type of FCM messages! The reason is that we have customized how the ANE works for best practices.
Overall, when working with the FCM ANE, you should think that you can send three types of messages to devices, Notification, Data and Mixed messages. When a device receives these messages, depending on the current status of your app on the device, the ANE will behave differently. To learn about these differences, you should read this page of our WIKI guide which will make you completely familiar with how you should treat the incoming messages.
Now that you know what kind of messages you can receive, it’s time to start developing your application with the FCM ANE.
How to use Advanced REST Client Software to Send FCM Messages
In real life scenarios, you will need a web server to send Data messages, or you may use the official Firebase Console to send Notification messages but when developing your app, you will need an easy workaround to send different kind of FCM messages. So it will speed up your development process. For this reason, you can build your own REST Client software OR simply use the Google Chrome app called the Advanced REST Client.
To install this small but helpful app, you should open this link in your Chrome browser. Data on that page will help you install the app in a few seconds. When installed, launch the app and you will see something like below.
To be able to send FCM messages, you need to connect to Google’s FCM endpoint address, so put “https://fcm.googleapis.com/fcm/send” into the Request URL field. The second thing you should remember is that you must send your request via POST. Therefore, chose the POST option. Next to the POST option, there is a dropdown menu (Custom content type), open it and select the “application/json” option.
Below those, you should enter your header request information. To do that, make sure the tab Raw Headers is selected and enter the following information:
You’re almost there. Now you should enter the data you wish to send. To do that, make sure the Raw payload tab is selected and enter the kind of FCM message you wish to send.
To send Notification messages:
To send Data messages:
To send Mixed messages:
If you want to learn how you should customize the information you are sending, your best source is the official Firebase documentation. In this page, it is explained in details that what does each parameter mean and how you can use them to customize your messages.
The good thing about the Advanced REST Client software is that it allows you to save your work! For instance, we are used to save three different requests, one for simple notifications, another one for Data messages and finally the third one for the Mixed messages. This way, we can easily switch between different types and send FCM messages quickly.
I’m sure you will find this trick very helpful when you are developing your application. After you made sure that everything related to FCM is working as expected, you may move your code to your own server.
Enjoy building AIR apps 🙂
MyFlashlabs Team.
Share this:
Related