android - 如何在Delphi Rio10.3.2中添加和删除Android通知 channel

标签 android delphi firebase-cloud-messaging firemonkey

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

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

在 RAD 10.3.2 中,新的选项/应用程序/服务参数提供了一个“默认本地通知 channel ID”,我想它是用来更改存储在构建或部署应用程序时生成的 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 时,我只需通过将其 id 写入 Default local notification channel 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/

相关文章:

android - 使用 Retrofit 测试 MVP Android

java - float 操作按钮 anchor

java - Java 中的 "How to format LocalDate with Custom Pattern"

delphi - 将 TWebBrowser 转换为 TWinControl

android - 无法解析 : play-services-tasks

java - 谷歌 GSON : How to use @Since annotation for e. g。版本 "1.2.1"? (无效双)

c# - 是否可以在 iPhone 和 OS X 上不使用 NIB 文件来创建窗口?

delphi - 静态类方法和常规例程指针的兼容性如何?

android - 如何在Xamarin Forms中保存通过推送通知接收的数据

javascript - 按客户端过滤网络通知