I'm sending FCM notifications from Kotlin native code in a Flutter app.
How can I open a Flutter terminated app by clicking on the notification that I have send through Kotlin native code?
Is there any way to achieve it?
Solution: I have solved it by using
FirebaseMessaging.instance.getInitialMessage().then((message) {
if (message != null) { // your logic }
});
Related
I have implemented firebase_messaging in my flutter application. Notifications are received in both android and iOS. I am using the following function for receiving notification.
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
print('onMessage: ${message.data}');
});
This function is getting called when notification is recevied in Android. But in iOS, this function is not getting called. Is there any fix available for this issue?
I am testing how my Flutter app handles notification using my Samsung Android 12 phone and Firebase Messaging campaign.
I have gotten this code (simplified) to work for a month and notification is handled properly.
FirebaseMessaging.instance.getInitialMessage().then((message) {
if (message != null) {
String? routeName = message.data["route"];
if (routeName != null) {
Navigator.of(context).pushNamed(routeName);
}
}
});
However, today when I wanted to change how handling notification works, I found out that the changes I made to this code are not reflected in the app when debugging through Flutter. Opening the app from a terminated state through the notification still behaves according to the old code above.
I have tried many things:
Uninstalling the app on Android
Removing all code related to Firebase Messaging
Clearing all app cache and data
But the app still keeps the behavior of the old code. Is there anything I can do to reset the behavior of FirebaseMessaging.instance.getInitialMessage() ?
I am creating a web app in flutter. It is used for entering students' attendance into the database.
What I want to achieve is to send SMS to the parents of absent students. I came upon flutter_sms 2.3.1 and it is supported for Android, iOS and web as per the pub.dev docs but I could not find any reference about sending SMS in flutter web using the same package. Please let me know if there is any way to achieve this task that I want.
Following is the code for sending the SMS but not working in Flutter web.
void _sendSMS(String message, List<String> recipents) async {
String _result = await sendSMS(message: message, recipients: recipents)
.catchError((onError) {
print(onError);
});
print(_result);
}
Twilio API would totally help you sending sms/whatsapp messages from any plaform automatically
I have an app that was using firebase messaging 7.0.3 and all worked perfectly. But when I migrated to firebase messaging 9.0.0, the push notifications are not being handled.
I know that the app is correctly linked to firebase and cloud messaging because in background I see the push notification comming, the problem is when I click that notification the app don't handle this event. Also, when the app is in foreground, the event of receiving the notification is not being triggered.
Specifically, the functions FirebaseMessaging.onMessage and FirebaseMessaging.onMessageOpenedApp are not working. My code is:
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
print("notification: message");
});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
print("notification: resume");
});
The prints are never called, and if I put some more code inside isn't executed too.
I also call FirebaseMessaging.getToken and I can get the token, plus when the app is in background I get the push notification, so is not a link problem with firebase. In the logs, when I receive the push I can see a message saying: Broadcast received for message. So I assumed that the push is arriving in all the occasions, and I am doing something wrong in the code.
I tested all cases in Android and iOS physical devices.
Someone know why this occurs?
I came across this exact same issue after migrating and upgrading to 9.0.0.
There is a minor issue with 9.0.0 plugin.
The fix can be found here:
https://github.com/FirebaseExtended/flutterfire/issues/4949
To cut a long story short, if you navigate to the definition of the factory
RemoteMessage.fromMap() Using Cmd+Click or Ctrl+Click while hovering over the RemoteMessage class with the mouse), in the return statement, change contentAvailable: map['contentAvailable'], to contentAvailable: map['contentAvailable']??false.
Notifications are now working for me again now.
This should work for you until the plugin is fixed.
I am creating an app using Phonegap 3.1, Sencha 2.3 for the platform android and iPhone.
For sending notification, i have used pushwoosh service and followed this link (http://www.pushwoosh.com/programming-push-notification/ios/ios-configuration-guide/)
Notification are getting perfectly on both Android and iPhone devices (whether app is running or not).
But the problem is, when I reinstall the app, i am not able to get notifications when the app is running and notifications are getting when app is minimized or not running.
In my index.html file, I have used this code to receive the notification while app is running.
document.addEventListener('push-notification', function(event) {
alert('push-notification');
var notification = event.notification;
navigator.notification.vibrate(1500);
navigator.notification.confirm(
notification.aps.alert, // message
alertDismissed, // callback
'ThisApp', // title
'Done' // buttonName
);
pushNotification.setApplicationIconBadgeNumber(0);
});
function alertDismissed() {
//do something after Done button pressed
}
After reinstall the app this listener is not calling.
I am not getting what actually missing in there, please advise.