Reputation: 2697
I try to setup push notification to my mobile apps using flutter firebase messaging.
I have doing below things :
However, when I try send message from firebase console, my mobile phone not showing the notification.
By debugging I can see my mobile phone receive the push notif :
I/flutter (17004): on message {notification: {body: message 18, title: test 18}, data: {}}
I/flutter (17004): on message {notification: {body: message 19, title: test 19}, data: {}}
I/flutter (17004): on message {notification: {body: message 20, title: test 20}, data: {}}
But it show nothing on my mobile phone.
My flutter code at home screen :
class HomeScreen extends StatefulWidget {
@override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
FirebaseMessaging _firebaseMessaging = new FirebaseMessaging();
@override
void initState() {
// TODO: implement initState
super.initState();
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) {
print('on message $message');
//_showItemDialog(message);
},
onResume: (Map<String, dynamic> message) {
print('on resume $message');
//_showItemDialog(message);
},
onLaunch: (Map<String, dynamic> message) {
print('on launch $message');
//_showItemDialog(message);
},
);
_firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(sound: true, badge: true, alert: true));
_firebaseMessaging.getToken().then((token){
print('>>>token='+token);
});
}
...
}
I have tried to send messaging using FCM API via postman, but same result (get message in debug console, but not in mobile phone)
Any idea how to solve ?
Upvotes: 4
Views: 4833
Reputation: 10463
To add on what has been mentioned in the comments, Firebase Cloud Messaging Android SDK won't display the message on the notification tray if the app is running on the foreground. Though the FCM SDK will still be able to receive the payload through the onMessage event, as displayed in the logs.
If you'd still like to display a notification while the app is visible, you can handle the onMessage event and display the payload using flutter_local_notificaions
plugin. You can check this documentation on how to handle this use case for newer versions of firebase_messaging
.
Upvotes: 2