2017-02-13 6 views
0

Firebaseの通知で、アプリケーションがバックグラウンドのときに通知を受け取りましたが、通知のタップなしにアプリケーションを開くと、データはIONIC androidアプリケーションに反映されません。IONIC android FCM

アプリケーションがフォアグラウンドの場合、データは自動的に反映されます。

私はcordova-plugin-messagingプラグインも使用していますが、動作しません。

window.cordova.plugins.firebase.messaging.onMessage(関数を(:私は

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); 
     } 
    ); 

を用いており、また、使用

データ){

 console.log(data); 

}); 

フォアグラウンドと通知をクリックしたとき。

アプリがバックグラウンドで、アプリが開いているときに通知をクリックしないでデータを取得したい。答えアンドロイド(src ->android-> MyFirebaseMessagingService.java)ファイルをプラグインあなたのAndroidのネイティブファイル(MyFirebaseMessagingService.java)とコルドバのコードの上に置く

+0

こんにちは。関連するコードスニペットを投稿してください。 –

+0

FCMPlugin.onNotification( 機能(データ){ IF(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); 

ため

おかげで、makeは上記の手段を変更した場合、アプリがバックグラウンドで動作しているあなたは、通知の平均値をプッシュしますアプリは自動的に開かれます。