Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
NotificationMessageAndroid.cs
2
4{
11 {
16 {
17 }
18
26 public string ChannelId { get; set; }
27
33 public string Sound { get; set; }
34
42 public string Tag { get; set; }
43
47 public string Color { get; set; }
48
54 public string BodyLocalizationKey { get; set; }
55
61 public string[] BodyLocalizationArguments { get; set; }
62
68 public string TitleLocalizationKey { get; set; }
69
75 public string[] TitleLocalizationArguments { get; set; }
76
82 public string Icon { get; set; }
83
87 public object AndroidSpecificDeliveryOptions { get; set; }
88
93 public override void ExportProperties(Dictionary<string, object> Message)
94 {
95 base.ExportProperties(Message);
96
97 Dictionary<string, object> AndroidConfig = Message.ContainsKey("android") && Message["android"] is Dictionary<string, object> ExistingAndroid
98 ? ExistingAndroid
99 : new Dictionary<string, object>();
100 Dictionary<string, object> AndroidNotification = new Dictionary<string, object>();
101
102 // Add Android-specific delivery options
103 AndroidConfig["priority"] = this.Priority.ToString().ToLower();
104
105 if (this.TimeToLive > 0)
106 AndroidConfig["ttl"] = this.TimeToLive + "s";
107
108 if (!this.SuppressNotification)
109 {
110 if (!string.IsNullOrEmpty(this.Title))
111 AndroidNotification["title"] = this.Title;
112
113 if (!string.IsNullOrEmpty(this.Body))
114 AndroidNotification["body"] = this.Body;
115
116 if (!string.IsNullOrEmpty(this.ClickAction))
117 AndroidNotification["click_action"] = this.ClickAction;
118
119 // Add notification properties
120 if (!string.IsNullOrEmpty(this.ChannelId))
121 AndroidNotification["channel_id"] = this.ChannelId;
122 else
123 AndroidNotification["channel_id"] = "default";
124
125 if (!string.IsNullOrEmpty(this.Sound))
126 AndroidNotification["sound"] = this.Sound;
127
128 if (!string.IsNullOrEmpty(this.Tag))
129 AndroidNotification["tag"] = this.Tag;
130
131 if (!string.IsNullOrEmpty(this.Color))
132 AndroidNotification["color"] = this.Color;
133
134 if (!string.IsNullOrEmpty(this.Icon))
135 AndroidNotification["icon"] = this.Icon;
136
137 if (!string.IsNullOrEmpty(this.BodyLocalizationKey))
138 {
139 AndroidNotification["body_loc_key"] = this.BodyLocalizationKey;
140
141 if (!(this.BodyLocalizationArguments is null))
142 AndroidNotification["body_loc_args"] = this.BodyLocalizationArguments;
143 }
144
145 if (!string.IsNullOrEmpty(this.TitleLocalizationKey))
146 {
147 AndroidNotification["title_loc_key"] = this.TitleLocalizationKey;
148
149 if (!(this.TitleLocalizationArguments is null))
150 AndroidNotification["title_loc_args"] = this.TitleLocalizationArguments;
151 }
152
153 if (AndroidNotification.Count > 0)
154 AndroidConfig["notification"] = AndroidNotification;
155 }
156
157 // Merge any additional Android-specific options
158 if (this.AndroidSpecificDeliveryOptions is Dictionary<string, object> Android2)
159 {
160 foreach (KeyValuePair<string, object> P in Android2)
161 {
162 if (AndroidConfig.TryGetValue(P.Key, out object Obj) &&
163 Obj is Dictionary<string, object> Obj1 &&
164 P.Value is Dictionary<string, object> Obj2)
165 {
166 foreach (KeyValuePair<string, object> P2 in Obj2)
167 Obj1[P2.Key] = P2.Value;
168 }
169 else
170 AndroidConfig[P.Key] = P.Value;
171 }
172 }
173
174 if (AndroidConfig.Count > 0)
175 Message["android"] = AndroidConfig;
176 }
177
184 public override bool TrySetProperty(string Name, object Value)
185 {
186 switch (Name)
187 {
188 case "android_channel_id":
189 case "channel_id":
190 case "channelId":
191 this.ChannelId = Value?.ToString();
192 return true;
193
194 case "sound":
195 this.Sound = Value?.ToString();
196 return true;
197
198 case "tag":
199 this.Tag = Value?.ToString();
200 break;
201
202 case "color":
203 this.Color = Value?.ToString();
204 break;
205
206 case "icon":
207 this.Icon = Value?.ToString();
208 return true;
209
210 case "body_loc_key":
211 this.BodyLocalizationKey = Value?.ToString();
212 return true;
213
214 case "body_loc_args":
215 if (Value is string[] BodyLocalizationArguments)
216 {
217 this.BodyLocalizationArguments = BodyLocalizationArguments;
218 return true;
219 }
220 break;
221
222 case "title_loc_key":
223 this.TitleLocalizationKey = Value?.ToString();
224 return true;
225
226 case "title_loc_args":
227 if (Value is string[] TitleLocalizationArguments)
228 {
229 this.TitleLocalizationArguments = TitleLocalizationArguments;
230 return true;
231 }
232 break;
233
234 case "android":
235 this.AndroidSpecificDeliveryOptions = Value;
236 break;
237 }
238
239 return base.TrySetProperty(Name, Value);
240 }
241 }
242}
string ChannelId
The notification's channel id (new in Android O).
string Color
The notification's icon color, expressed in #rrggbb format.
object AndroidSpecificDeliveryOptions
Android-specific delivery options.
string[] TitleLocalizationArguments
Variable string values to be used in place of the format specifiers in title_loc_key to use to locali...
string BodyLocalizationKey
The key to the body string in the app's string resources to use to localize the body text to the user...
string TitleLocalizationKey
The key to the title string in the app's string resources to use to localize the title text to the us...
string Sound
The sound to play when the device receives the notification.
override void ExportProperties(Dictionary< string, object > Message)
Prepares the object to send to Firebase.
string Icon
The URL to use for the notification's icon.
string Tag
Identifier used to replace existing notifications in the notification drawer.
string[] BodyLocalizationArguments
Variable string values to be used in place of the format specifiers in body_loc_key to use to localiz...
override bool TrySetProperty(string Name, object Value)
Tries to set a property value.
bool SuppressNotification
If the visual notification part should be suppressed (data-only/background).
string ClickAction
The action associated with a user click on the notification.
int TimeToLive
This parameter specifies how long (in seconds) the message should be kept in FCM storage if the devic...
NotificationPriority Priority
Sets the priority of the message. Valid values are "normal" and "high."