首页 > 解决方案 > Delphi Rio10.3.2中如何添加和删除Android通知通道

问题描述

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

RAD 10.3.2 现在为 API >= 26 提供了一些支持,并自动创建了“回退”通知通道。它的默认描述是“Firebase 的通知通道”,我想更改此描述并添加一些新通道。

在 RAD 10.3.2 中,新的 Options/Application/Services 参数提供了一个“默认本地通知通道 ID”,我想它可以更改在构建或部署应用程序时生成fcm_fallback_notification_channel_label的文件中存储的值。Strings.xml

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

但是,我仍然只有一个频道,我不知道如何添加更多频道。
我在 Android 支持中进行了搜索,发现通道应该是通过notificationManager.createNotificationChannel(channel)在应用程序的起始代码中添加的。
但是,我发现在 TPushService 或 TPushServiceConnection 中无法访问这些方法。Delphi 中是否有添加和删除通知通道的“标准”方式?

标签: androiddelphifirebase-cloud-messagingfiremonkey

解决方案



感谢 embarcadero 的支持,我得到了完整的答案。用于创建和删除通知通道的 Androïd 方法位于 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中写入其 id 来指定应用作后备通道的通道。Default local notification channel idProject > Options... > Application > Services

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

  • 应用程序收到push notification payload未设置gcm.notification.android_channel_id密钥且您未设置默认值的notification channel id
  • 应用程序收到一个push notification payload没有设置gcm.notification.android_channel_id密钥的,你设置了一个默认值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尚未在代码中创建默认值

推荐阅读