android 当应用程序关闭或在 Flutter 中终止时,带有视频通话操作按钮的通知对话框

8wtpewkr  于 2023-05-05  发布在  Android
关注(0)|答案(2)|浏览(166)

bounty还有6天到期。回答此问题可获得+50声望奖励。fahim irfan希望引起更多关注这个问题。

我正在使用Flutter WebRTC进行视频通话。视频通话工作正常。当应用程序运行后台或应用程序关闭时,我使用Firebase Cloud Messaging,我使用Firebase消息包。当应用程序关闭并运行后台时,我收到推送通知。但是我无法显示像WhatsApp/ Skype/ Messenger通知对话框这样的对话框。我正在使用flutter本地通知包来显示推送通知。x1c 0d1x我想显示一个对话框中所示的图片。
此外,当应用程序关闭时,如果点击推送通知,我想重定向到所需的页面。此时,它将重定向到初始屏幕,然后是主屏幕,最后是所需的屏幕。我怎么能一开始就重定向?

izj3ouym

izj3ouym1#

可以使用firebase_messagingawesome_notifications
在你的firebase后台订阅处理程序中添加这个

await AwesomeNotifications().createNotification(
  content: NotificationContent(
    id: createuniqueId(),
    channelKey: 'basic_channel',
    title: message.data['title'],
    body: message.data['body'],
    wakeUpScreen: true,
    fullScreenIntent: true,
    autoDismissible: false,
    category: NotificationCategory.Call,
    locked: true,
    displayOnForeground: true,
  ),
  actionButtons: [
    NotificationActionButton(
      key: 'accept',
      label: 'Accept',
    ),
    NotificationActionButton(
      isDangerousOption: true,
      key: 'reject',
      label: 'Reject',
    ),
  ],
);

在main()中添加此内容

AwesomeNotifications().initialize(
    'resource://drawable/ic_icon',
    [
      NotificationChannel(
        channelKey: 'basic_channel', 
        channelName: 'Basic Notification', 
        channelDescription: 'Hello world',
        importance: NotificationImportance.High,
        channelShowBadge: true,
        vibrationPattern: highVibrationPattern
      ),
    ]
  );
t3psigkw

t3psigkw2#

flutter_local_notifications示例:
机器人

Future<void> _showNotificationWithActions() async {
  const AndroidNotificationDetails androidNotificationDetails =
      AndroidNotificationDetails(
    '...',
    '...',
    '...',
    actions: <AndroidNotificationAction>[
      AndroidNotificationAction('id_1', 'Action 1'),
      AndroidNotificationAction('id_2', 'Action 2'),
      AndroidNotificationAction('id_3', 'Action 3'),
    ],
  );
  const NotificationDetails notificationDetails =
      NotificationDetails(android: androidNotificationDetails);
  await flutterLocalNotificationsPlugin.show(
      0, '...', '...', notificationDetails);
}

伊奥斯

final DarwinInitializationSettings initializationSettingsDarwin = DarwinInitializationSettings(
    // ...
    notificationCategories: [
    const DarwinNotificationCategory(
        'demoCategory',
        <DarwinNotificationAction>[
            DarwinNotificationAction('id_1', 'Action 1'),
            DarwinNotificationAction(
            'id_2',
            'Action 2',
            options: <DarwinNotificationActionOption>{
                DarwinNotificationActionOption.destructive,
            },
            ),
            DarwinNotificationAction(
            'id_3',
            'Action 3',
            options: <DarwinNotificationActionOption>{
                DarwinNotificationActionOption.foreground,
            },
            ),
        ],
        options: <DarwinNotificationCategoryOption>{
            DarwinNotificationCategoryOption.hiddenPreviewShowTitle,
        },
    )
],

在iOS上,需要在使用initialize方法启动应用程序之前配置通知操作

相关问题