2017-02-13 121 views
0

在Firebase通知中,在應用程序是背景的時候得到了通知,但是當我沒有通知的點擊打開應用程序時,數據在IONIC android應用程序中不反映。IONIC android FCM通知

當應用程序是前臺時,數據會自動反映。

我也使用了cordova-plugin-messaging插件,但沒有工作。

我已經使用

FCMPlugin.onNotification( 功能(數據){

  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(函數(數據){

 console.log(data); 

}); 

,但它的工作原理,當應用程序是在前景和當我們點擊通知..

我想檢索數據時,應用程序是背景,並沒有點擊通知時,應用程序打開。

謝謝回答

+0

嗨。請發佈相關的代碼片段。 –

+0

FCMPlugin.onNotification( 功能(數據){ 如果(data.wasTapped){ 的console.log(數據); }否則{ 的console.log(數據); } }, 函數(MSG){ 的console.log( '成功註冊onNotification回調:' + MSG); }, 函數(ERR){ 的console.log( '錯誤註冊onNotification回調:' + ERR); } ) ; – user1981110

+0

如果用戶在應用程序死亡/未運行時收到通知,如果應用程序在未點擊通知的情況下打開,則數據將不會發送至應用程序。這是正常的行爲。 – Akil

回答

0

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)和科爾多瓦插件的Android (src ->android-> MyFirebaseMessagingService.java)文件,如果使上面的修改手段,應用程序是在後臺你推通知的意思應用程序將自動打開。