Reputation: 1282
My issue seems similar to this firebase_messaging onResume and onLaunch not working however I don't think the solution work for me since I'm already trying to access the fields in data property.
I'm currently displaying a push notification to users when the app is running and that part is working fine. However I also want to show a notification when the app is in the background and when the user clicks on it, they should be greeted with an alert message.
In the onResume method if I do this, it works and when I open the notification I see the message printed on the console and also the Alert message
onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
Alert(context: context, title: 'Hi User!').show();
}
However, if I try to access the data property in the title, I do see the message printed on the console but I don't see any Alert now
onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
Alert(context: context, title: message['data']['user']['name']).show();
}
The same piece of code works when the app is running in the onMessage
property however for both onLaunch
and onResume
I see the above described behavior. Below are the logs from the console
W/awesome_projec(13005): Accessing hidden method Landroid/os/WorkSource;->add(I)Z (light greylist, reflection)
W/awesome_projec(13005): Accessing hidden method Landroid/os/WorkSource;->add(ILjava/lang/String;)Z (light greylist, reflection)
W/awesome_projec(13005): Accessing hidden method Landroid/os/WorkSource;->size()I (light greylist, reflection)
W/awesome_projec(13005): Accessing hidden method Landroid/os/WorkSource;->get(I)I (light greylist, reflection)
W/awesome_projec(13005): Accessing hidden method Landroid/os/WorkSource;->getName(I)Ljava/lang/String; (light greylist, reflection)
E/FlutterFcmService(13005): Fatal: failed to find callback
W/FirebaseMessaging(13005): Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.
E/FlutterFcmService(13005): Fatal: failed to find callback
I/flutter (13005): onResume: {notification: {}, data: {collapse_key: com.example.awesome_project, google.original_priority: high, google.sent_time: 15751462256, google.delivered_priority: high, google.ttl: 2419200, from: 554610817622, location: {"latitude":24.6351,"longitude":70.2764}, user: {"phoneNumber":"1274545332","name":"Bobby94"}, google.message_id: 0:157514622564xxx}}
Upvotes: 6
Views: 4739
Reputation: 31
One way to work is: in the payload put into data for example:
"data": {
"click_action": "FLUTTER_NOTIFICATION_CLICK",
"id": "1",
"status": "done",
"message": "My Message",
"title": "Meu Title"
}
Than use ${message['data']['message']}'
instead of ${message['notification']['body']}'
.
Upvotes: 0
Reputation: 86
in firebaseMessaging version ^4,
the click_action only put in data, on in notification anymore. If you still put it in notification, you can not go another page you want,
{
notification: {
title: 'Title',
body: 'Body',
},
body :
{
click_action :FLUTTER_NOTIFICATION_CLICK,
message: message from firebase
}
}
Upvotes: 0
Reputation: 149
You have to add new key value click_action: 'FLUTTER_NOTIFICATION_CLICK'
in notification payload. like following
{
notification: {
title: 'Title',
body: 'Body',
click_action: 'FLUTTER_NOTIFICATION_CLICK'
}
}
Also add following code on manifest file inside activity tag
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Upvotes: 2