android - 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 中是否有添加和删除通知通道的“标准”方式?
解决方案
感谢 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 id
Project > 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
尚未在代码中创建默认值
推荐阅读
- python - 消除对象的阴影轮廓
- typescript - 用于操作对象的索引签名
- c# - Visual Studio ClickOnce 发布失败
- java - 解决了不和谐 onGuildMemberJoinEvent 不起作用
- json - xml2js 到 JSON 的转换:无法设置未定义的属性“”
- asp.net-core - AutoMapper - IMapper.Map 上非常零星的 StackOverflowException
(...) 称呼 - php - PHP file_get_contents() 在发出 GET 请求时忽略请求正文
- google-apps-script - Google 应用 为许多用户部署脚本网络应用
- rust - Rust:如何将字节连接在一起
- android - 试图让 RecyclerView 使用不同的数据集