I'm using Phonegap and FCM to send push notification in android. Currently I'm receiving push notification and it's redirecting me to a page at tapping on the notification when the app is active. But when in background or closed, it just opens the index page of the app and doesn't redirect to my page.
Here are my codes,
index.js
var app = {
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
document.addEventListener("pause", this.onPause, false);
document.addEventListener("resume", this.onResume, false);
},
onDeviceReady: function() {
window.FirebasePlugin.getToken(function(token) {
document.getElementById("deviceToken").value = token;
}, function(error) {
console.error(error);
});
},
onPause: function() {
window.FirebasePlugin.onNotificationOpen(function(notification) {
window.location.href = "orders.html"; // Redirecting to this page on notification
}, function(error) {
console.error(error);
});
},
onResume: function() {
window.FirebasePlugin.onNotificationOpen(function(notification) {
window.location.href = "orders.html"; // Redirecting to this page on notification
}, function(error) {
console.error(error);
});
},
}
index.html
<body>
<div class="app" style="display: none;">
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
<input type="hidden" id="deviceToken" />
</div>
</div>
<script src="cordova.js"></script>
<script src="js/index.js"></script>
<script>
app.initialize();
</script>
</body>
Is there anything wrong in my code? How can I redirect to my page upon tapping the notification when app is in background or closed?