tl;dr
data
にkey:click_action
でvalue:FLUTTER_NOTIFICATION_CLICK
を入れろ
詳細
Flutter でFirebase Cloud Messaging(FCM)をの初期設定をしました.
そしてプッシュ通知を受信する際は以下のコードになります.
_firebaseMessaging.configure( onMessage: (Map<String, dynamic> message) async { print("firebase onMessage Content = $message"); }, onLaunch: (Map <String ,dynamic>message) async { print("firebase onLaunch Content = $message"); }, onResume: (Map<String,dynamic> message) async { print("firebase onResume Content =$message"); });
デバイストークンを取得してFirebase Consoleから通知を送ります.
アプリがバックグランド時に通知を受け取ることができます.
AndroidManifest.xmlに適切に設定して,通知をタップするとアプリを開くことができます.
アプリがフォアグラウンド時,onMessage
で通知の情報を受け取れましたが
バックグラウンド時にシステム通知トレイからタップによるアプリ起動でonLaunch,onResume
が起動しない問題が発生.
解決
公式に書いてました.
Refer to the Firebase documentation about FCM for all the details about sending messages to your app. When sending a notification message to an Android device, you need to make sure to set the click_action property of the message to FLUTTER_NOTIFICATION_CLICK. Otherwise the plugin will be unable to deliver the notification to your app when the users clicks on it in the system tray.
data
にkey:click_action
でvalue:FLUTTER_NOTIFICATION_CLICK
を設定する必要があります.
Firebase Consoleだとこう
※typeは関係ないです.