我想在 FMX 项目上为 Android 实现多个通知 channel 。
RAD 10.3.2 现在为 API >= 26 提供了一些支持,并自动创建了“回退”通知 channel 。它的默认描述是“Firebase 的通知 channel ”,我想更改此描述并添加一些新 channel 。
在 RAD 10.3.2 中,新的 Options/Application/Services 参数提供了一个“默认本地通知 channel ID”,我想它可以更改 fcm_fallback_notification_channel_label
的值。存储在 Strings.xml
构建或部署应用程序时生成的文件。
但是,当我在此字段中写入类似“Infos”的 Id 时,这对生成的 Strings.xml
没有影响文件内容。
因此,我复制了 Strings.xml
另一个目录中的文件,手动编辑它并修改部署以使用此文件而不是自动文件。
如果我卸载应用程序并使用更改的 channel 描述重新安装它,这将起作用。最终用户现在可能会看到正确的 channel 名称。
但是,我仍然只有一个 channel ,我不知道如何添加更多 channel 。
我在 Android 支持中进行了搜索,发现 channel 应该通过 notificationManager.createNotificationChannel(channel)
添加。在应用程序的起始代码中。
但是,我发现在 TPushService 或 TPushServiceConnection 中无法访问这些方法。 Delphi 中是否有添加和删除通知 channel 的“标准”方式?
最佳答案
感谢 embarcadero 的支持,我得到了完整的答案。
用于创建和删除通知 channel 的 Androïd 方法位于 TNotificationCenter 对象中,该对象创建用于拦截设备 token 以及在应用程序运行时收到的通知。
以下方法可用:
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
创建通知 channel 时,我只需要通过在 Default local notification channel id
中写入其 ID 来指定应用作后备 channel 的 channel 。在 Project > Options... > Application > Services
项目参数。默认回退通知 channel 仅在以下情况下由 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
未在代码中创建关于android - Delphi Rio10.3.2中如何添加和删除Android通知 channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57670486/