如何在 Delphi Rio10.3.2 中添加和删除 Android 通知渠道

How to add and remove Android notification channels in Delphi Rio10.3.2

我想在 FMX 项目上为 Android 实现多个通知渠道。

RAD 10.3.2 现在为 API >= 26 提供了一些支持,并且会自动创建一个 "fallback" 通知渠道。它的默认描述是 "Notification channel for Firebase",我想更改此描述并添加一些新频道。

在RAD 10.3.2中,新的Options/Application/Services参数提供了一个"Default local notification channel Id",我想,它是用来改变存储在[=13中的fcm_fallback_notification_channel_label的值的=] 构建或部署应用程序时生成的文件。

但是,当我在这个字段中写一个像"Infos"这样的Id时,这对生成的Strings.xml文件内容没有影响。
因此,我将 Strings.xml 文件复制到另一个目录,手动编辑它并修改部署,以便使用此文件而不是自动文件。
如果我卸载应用程序并使用更改后的频道描述重新安装它,这将起作用。最终用户现在可以看到正确的频道名称。

可是我还是只有一个频道,不知道怎么添加更多的。
我在 Android 支持中进行了搜索,发现频道应该通过应用程序起始代码中的 notificationManager.createNotificationChannel(channel) 添加。
但是,我发现无法在 TPushService 或 TPushServiceConnection 中访问这些方法。 Delphi 中是否有 "standard" 方法用于添加和删除通知渠道?


感谢 embarcadero 的支持,我得到了完整的答案。 用于创建和删除通知通道的 Android 方法位于为拦截设备令牌而创建的 TNotificationCenter 对象中,以及在应用程序处于 运行.
时收到的通知。 可以使用以下方法:

function CreateChannel: TChannel; overload;
function CreateChannel(const AId: string; const ATitle: string; const ADescription: string = ''): TChannel; overload;
procedure CreateOrUpdateChannel(const AChannel: TChannel);
procedure DeleteChannel(const AChannelId: string);
procedure GetAllChannels(const AChannels: TChannels);

当我用 CreateOrUpdateChannel 创建了我的通知渠道后,我只需要通过在 Project > Options... > Application > Services 中的 Default local notification channel id 中写入其 ID 来指定将用作后备渠道的渠道=] 项目参数.

默认回退通知通道仅在以下情况下由 Delphi/C++ Android 堆栈创建:

  • 应用程序收到一个 push notification payload,它没有设置 gcm.notification.android_channel_id 键并且您还没有设置默认值 notification channel id
  • 应用程序收到一个没有设置gcm.notification.android_channel_id键的push notification payload,你已经设置了一个默认的notification channel id,但是默认的notification channel还没有被创建代码
  • 应用程序接收到 push notification payload 设置 gcm.notification.android_channel_id 键,notification channel 尚未在代码中创建,并且您尚未设置默认值 notification channel id
  • 应用程序收到一个push notification payload设置了gcm.notification.android_channel_id键,那个notification channel还没有在代码中创建,你已经设置了一个默认的notification channel id,但是默认的 notification channel 没有在代码中创建