我正在使用Phonegap
& FCM
在android中发送推送通知。目前我正在收到推送通知&当应用程序处于活动状态时,它会将我重定向到点击通知的页面。但是在后台或关闭时,它只会打开应用程序的索引页面,而不会重定向到我的页面。这是我的代码,
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>
我的代码有什么问题吗?当app处于后台或关闭时,如何在点击通知时重定向到我的页面?急需帮助!谢谢!