英文:
Action Buttons not showing in notification when application is in background in real device, using awesome_notifications package in Flutter
问题
我在我的flutter
应用程序中使用awesome_notifications
包来显示通知,并使用firebase_messaging
触发我的通知,所以每当触发Firebase云消息时,我会在我的设备上收到通知。我遇到的问题如下:
问题 - 当我的应用程序在后台模式下运行时(在我的模拟器中,即Android Studio模拟器),通知中会显示操作按钮,但当我在真实设备上运行相同的应用程序并将其放入后台,然后使用Firebase触发通知时,我会收到通知,但操作按钮不会显示。我被这个问题困扰,如果有人能帮助我,我将不胜感激。
实现 - 我在FirebaseMessaging.onBackgroundMessage()
函数中调用了AwesomeNotifications().createNotification()
函数,以便在我的应用程序在后台运行时显示通知。
我真的非常感激所有的帮助。
我已经在线搜索了所有可能的解决方案,但仍然面临相同的问题,我还尝试使用awesome_notifications_fcm
包,但也没有帮助。
英文:
I am using awesome_notifications
package in my flutter
application to show notifications and I am triggering my notifications using firebase_messaging
, so whenever firebase cloud messaging is triggered I get notification on my device. The ISSUE I am facing is as below :-
ISSUE - Action Buttons are being displayed in my notification when the application is in background mode on my Emulator(Android Studio Emulator) BUT when I run the same application on a real device and I put application in background and trigger a notification using firebase I do get the notification but ACTION BUTTONS ARE NOT DISPLAYED. I am stuck with this issue if someone can please help.
IMPLEMENTATION - I am calling AwesomeNotifications().createNotification()
function inside FirebaseMessaging.onBackgroundMessage()
function. to show notification even when my application is in background .
I would really appreciate all the help
I have searched online for all the possible solutions but still facing the same issues, I have also tried using the awesome_notifications_fcm
package but it was of no help too.
答案1
得分: 1
你尝试将NotificationContent中的actionType设置为SilentBackgroundAction吗?如下所示:
AwesomeNotifications().createNotification(
content: NotificationContent(
id: 1,
channelKey: "some-key",
actionType: ActionType.SilentBackgroundAction,
),
);
正如文档中所说:"不要强制将应用程序切换到前台,并在独立的Dart隔离中运行,不接受任何视觉元素。执行完全独立于应用程序生命周期,如果应用程序被终止/杀死,将不会中断。"
英文:
Have you tried setting actionType in NotificationContent to SilentBackgroundAction like below?
AwesomeNotifications().createNotification(
content: NotificationContent(
id: 1,
channelKey: "some-key",
actionType: ActionType.SilentBackgroundAction,
),
);
As it says in documentation "Do not forces the app to go foreground and runs on an exclusive dart isolate and do not accept any visual element. The execution is totally apart from app lifecycle and will not be interrupt if the app goes terminated / killed."
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论