【问题标题】:Add button to notification in flutter_foreground_task在 flutter_foreground_task 中向通知添加按钮
【发布时间】:2022-11-09 05:30:53
【问题描述】:

如何在 AndroidNotificationOptions 中添加名为“断开连接”的按钮?

我的简单代码在这里。

const AndroidNotificationOptions(
  channelId: 'parameter_channel',
  channelName: 'Parameters',
  channelDescription: 'This notification appears when the reading begaz params running.',
  channelImportance: NotificationChannelImportance.LOW,
  priority: NotificationPriority.LOW,
  visibility: NotificationVisibility.VISIBILITY_PRIVATE,
  playSound: false,
  enableVibration: false,
  iconData: NotificationIconData(
    resType: ResourceType.mipmap,
    resPrefix: ResourcePrefix.ic,
    name: 'launcher',
  ),
),

在这里我使用flutter_foreground_task。

【问题讨论】:

    标签: flutter flutter-dependencies


    【解决方案1】:

    如果您查看文档,您将看到一个示例,但在您的情况下应该是这样的:

    androidNotificationOptions: AndroidNotificationOptions(
          channelId: 'notification_channel_id',
          channelName: 'Foreground Notification',
          channelDescription: 'This notification appears when the foreground service is running.',
          channelImportance: NotificationChannelImportance.LOW,
          priority: NotificationPriority.LOW,
          iconData: const NotificationIconData(
            resType: ResourceType.mipmap,
            resPrefix: ResourcePrefix.ic,
            name: 'launcher',
          ),
          buttons: [
            const NotificationButton(id: 'disconnect', text: 'Disconnect'),
          ],
        ),
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多