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

∥☆過路亽.° 提交于 2021-01-27 21:10:04

问题


I would like to implement multiple notification channels for Android on an FMX project.

RAD 10.3.2 now provides some support for API >= 26 and a "fallback" notification channel is automatically created. Its default description is "Notification channel for Firebase" and I would like to change this description as well as to add some new channels.

In RAD 10.3.2, the new Options/Application/Services parameters provide a "Default local notification channel Id" which, I suppose, is there to change the value of the fcm_fallback_notification_channel_label stored in the Strings.xml file generated when building or deploying the App.

However, when I write an Id like "Infos" in this field, this has no effect on the generated Strings.xml file content.
I've thus copied the Strings.xml file in another directory, edited it manually and modified the deployment in order to use this file rather than the automatic one.
This is working if I uninstall the App and reinstall it with the changed channel description. The final user may now see the correct name of the channel.

However, I've still got only one channel and I don't know how to add more ones.
I've searched in the Android support and I see that the channels are supposed to be added via notificationManager.createNotificationChannel(channel) in the starting code of an App.
However, I've found no access to these method in TPushService or TPushServiceConnection. Is there a "standard" way in Delphi for adding and removing notification channels ?


回答1:



Thanks to embarcadero support, I've got a full answer. The Androïd methods for creating and removing notification channels are located in the TNotificationCenter object created to intercept the device token as well as the notifications received while the application is running.
The following methods are available :

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);

When I've created my notification channels with CreateOrUpdateChannel, I just have to specifiy the one which shall be used as the fallback channel by writing its id in Default local notification channel id in the Project > Options... > Application > Services projet parameters.

The default fallback notification channel is only created by Delphi/C++ Android stack in the following cases:

  • The application receives a push notification payload that does not set the gcm.notification.android_channel_id key and you have not set a default notification channel id
  • The application receives a push notification payload that does not set the gcm.notification.android_channel_id key, you have set a default notification channel id, but the default notification channel has not been created in the code
  • The application receives a push notification payload that sets the gcm.notification.android_channel_id key, that notification channel has not been created in the code, and you have not set a default notification channel id
  • The application receives a push notification payload that sets the gcm.notification.android_channel_id key, that notification channel has not been created in the code, you have set a default notification channel id, but the default notification channel has not been created in the code


来源:https://stackoverflow.com/questions/57670486/how-to-add-and-remove-android-notification-channels-in-delphi-rio10-3-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!