[英]IONIC android FCM notification
在Firebase通知中,當應用程序處於后台時我收到通知,但是當我打開應用程序而沒有點擊通知時,數據無法反映在IONIC android應用程序中。
當應用程序是前台時,數據將自動反映。
我也使用了cordova-plugin-messaging插件,但沒有用。
我用過
FCMPlugin.onNotification(function(data){
if(data.wasTapped){
console.log(data);
}else{
console.log(data);
}
},
function(msg){
console.log('onNotification callback successfully registered: ' + msg);
},
function(err){
console.log('Error registering onNotification callback: ' + err);
}
);
並用於:
window.cordova.plugins.firebase.messaging.onMessage(function(data){
console.log(data);
});
但適用於當應用程序為前台以及我們單擊通知時的情況。
我想在應用程序為后台時檢索數據,並且在應用程序打開時不單擊通知。
感謝您的回答
sendPushPayload( data );
Intent NotificationIntent = new Intent(this, FCMPluginActivity.class)
.addCategory(Intent.CATEGORY_LAUNCHER)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
for (String key : data.keySet()) {
NotificationIntent.putExtra(key, data.get(key).toString());
}
startActivity(NotificationIntent);
將上面的代碼放入您的android本機文件(MyFirebaseMessagingService.java )
和cordova插件android (src ->android-> MyFirebaseMessagingService.java)
文件中,如果進行上述更改,則該應用處於后台運行,您推送通知意味着該應用將自動打開。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.