Push Notification using Cordova and Google Firebase
Push Notification using Cordova and Google Firebase
Technical Articles
Rahul Patra
November 28, 2019 5 minute read
Hi Readers!
First of all, thank you very much for reading this blog. I hope it will be helpful for you.
As a Fiori developer, if you are building any Hybrid Mobile Application, Push Noti cation will be one of the
hot features. In this Blog I am going to showcase how to integrate Google Firebase Push Noti cation in your
Android device.
So Let’s Start….
Your system must be con gured to build a hybrid mobile application. In case it’s not, follow the below link to
con gure that.
https://evothings.com/doc/build/cordova-install-windows.html
Once the system con gured, check the cordova version and cordova android version.
Cordova: 9.0.0
Use the bellow command to create a new cordova application. Remember the package name
com. ori.pushnoti cation this is going to be used in up-coming steps.
https://blogs.sap.com/2019/11/28/sap-ui5-push-notification-using-google-firebase-android/ 1/17
5/7/2020 SAP UI5 Push Notification using Cordova and Google Firebase – Android | SAP Blogs
Once the application created, you can nd the app in the respective directory.
These will be the default folder of that application. Now, Open the app in your cmd.
cd pushnotification
https://blogs.sap.com/2019/11/28/sap-ui5-push-notification-using-google-firebase-android/ 2/17
5/7/2020 SAP UI5 Push Notification using Cordova and Google Firebase – Android | SAP Blogs
https://blogs.sap.com/2019/11/28/sap-ui5-push-notification-using-google-firebase-android/ 3/17
5/7/2020 SAP UI5 Push Notification using Cordova and Google Firebase – Android | SAP Blogs
1. Let’s add a android app to the rebase project. Select the android Icon.
2. Use the same package name that you have used while creating cordova mobile app.
https://blogs.sap.com/2019/11/28/sap-ui5-push-notification-using-google-firebase-android/ 4/17
5/7/2020 SAP UI5 Push Notification using Cordova and Google Firebase – Android | SAP Blogs
https://blogs.sap.com/2019/11/28/sap-ui5-push-notification-using-google-firebase-android/ 5/17
5/7/2020 SAP UI5 Push Notification using Cordova and Google Firebase – Android | SAP Blogs
https://blogs.sap.com/2019/11/28/sap-ui5-push-notification-using-google-firebase-android/ 6/17
5/7/2020 SAP UI5 Push Notification using Cordova and Google Firebase – Android | SAP Blogs
Now, you need to add couple of rebase plugins to the app. Use the below commands. For more information
visit http://cordova-plugin- rebase-lib
Note: Remember your cordova setup must be below to install the plugins.
Now, you need to run the application, execute the below command.
cordova run
Once that application successfully build and deployed in your device then go to your rebase console.
https://blogs.sap.com/2019/11/28/sap-ui5-push-notification-using-google-firebase-android/ 7/17
5/7/2020 SAP UI5 Push Notification using Cordova and Google Firebase – Android | SAP Blogs
Click on Next
Follow RSS feed Like
https://blogs.sap.com/2019/11/28/sap-ui5-push-notification-using-google-firebase-android/ 8/17
5/7/2020 SAP UI5 Push Notification using Cordova and Google Firebase – Android | SAP Blogs
4. Click Next
5. Go to Final Preview
https://blogs.sap.com/2019/11/28/sap-ui5-push-notification-using-google-firebase-android/ 9/17
5/7/2020 SAP UI5 Push Notification using Cordova and Google Firebase – Android | SAP Blogs
6. Click on Publish
https://blogs.sap.com/2019/11/28/sap-ui5-push-notification-using-google-firebase-android/ 10/17
5/7/2020 SAP UI5 Push Notification using Cordova and Google Firebase – Android | SAP Blogs
Now, You able to trigger the Noti cation form Google Firebase, but how can you do the same from any
endpoint. You must know the device registration token for sending any noti cation.
https://blogs.sap.com/2019/11/28/sap-ui5-push-notification-using-google-firebase-android/ 11/17
5/7/2020 SAP UI5 Push Notification using Cordova and Google Firebase – Android | SAP Blogs
onDeviceReady: function() {
this.receivedEvent('deviceready');
window.FirebasePlugin.onTokenRefresh(function(token) {
// save this server-side and use it to push notifications to this device
console.log(token);
alert(token);
}, function(error) {
console.error(error);
});
},
SO, now you can able to nd the unique device registration token for your device.
https://blogs.sap.com/2019/11/28/sap-ui5-push-notification-using-google-firebase-android/ 12/17
5/7/2020 SAP UI5 Push Notification using Cordova and Google Firebase – Android | SAP Blogs
https://blogs.sap.com/2019/11/28/sap-ui5-push-notification-using-google-firebase-android/ 13/17
5/7/2020 SAP UI5 Push Notification using Cordova and Google Firebase – Android | SAP Blogs
STEP 10: Send Data Message using HTTP protocol with POSTMAN
Follow RSS feed Like
In case you doesn’t have POSTMAN installed in your system, please nd the below URL to add POSTMAN in
your Google Chrome web browser as an add on.
https://chrome.google.com/webstore/detail/postman/fhbjgbi injbdggehcddcbncdddomop?hl=en
1. First, you have to copy Legecy Server Key from Firebase Console > Project Settings > Cloud Messaging
Note: Firebase has upgraded our server keys to a new version. You may continue to use your legacy server
key, but it is recommended that you upgrade to the newest version.
4. Add Headers
Content-Type: application/json.
https://blogs.sap.com/2019/11/28/sap-ui5-push-notification-using-google-firebase-android/ 14/17
5/7/2020 SAP UI5 Push Notification using Cordova and Google Firebase – Android | SAP Blogs
Alert Moderator
5. Now Select Body > raw > JSON (application/json) and add following code:
Assigned tags
{
"to"| : SAP
SAPUI5 "YOUR_FCM_TOKEN_WILL_BE_HERE",
Cloud Platform | SAP Fiori |
"collapse_key" : "type_a",
"notification" : {
"body"
Related Blog : "Body of Your Notification",
Posts
"title": "Title of Your Notification"
},
How to debug UI5 application packaged into a mobile device via Cordova with a custom plugin
"data" : {
By Jerry Wang , Aug 18, 2017
"body" : "BODY of your Notification in Data",
Phonegap + OpenUI5 = App published on Play store [Packaging SAPUI5 application]
"title": "Title of Your Notification in Title",
By Former Member , Dec 01, 2014
"key_1" : "Value for key_1",
Step by step to package a Fiori application into your Android device using Cordova
"key_2" : "Value for key_2"
By Jerry Wang , Aug 17, 2017
}
}
Related Questions
6. Now You can send a Noti cation using POSTMAN to your registered device.
—————————————————————————————————————————————————————
Not able to send push noti cations to individual user mobile app without IDP
————————————————————————————————————-
By Former Member , Nov 04, 2016
Rahul Patra
4 Comments
https://blogs.sap.com/2019/11/28/sap-ui5-push-notification-using-google-firebase-android/ 15/17
5/7/2020 SAP UI5 Push Notification using Cordova and Google Firebase – Android | SAP Blogs
Like(1)
Hemalatha Bharanikumar
Very helpful
Like(1)
Praveer Sen
Very informative.
Happy learning
Praveer
Like(0)
SAP Fiori
Thank you!
Like(0)
Find us on
https://blogs.sap.com/2019/11/28/sap-ui5-push-notification-using-google-firebase-android/ 16/17
5/7/2020 SAP UI5 Push Notification using Cordova and Google Firebase – Android | SAP Blogs
Newsletter Support
https://blogs.sap.com/2019/11/28/sap-ui5-push-notification-using-google-firebase-android/ 17/17