-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android: Cannot show notification when the App is in foreground #149
Comments
If you want them to be displayed on foreground just set:
PushNotificationManager.DefaultNotificationChannelImportance =
NotificationImportance.High
In the application class before intializing.
…On Fri, Jun 26, 2020, 5:37 AM Paul TO ***@***.***> wrote:
When the notification payload doesn't include priority or channel_id. I
expect that the notification will be shown if I set the
DefaultNotificationChannelImportance to high or above, but it doesn't.
After reading the source code, I suspect that the first if block in
OnReceived of DefaultPushNotificationHandler is wrongly written, as shown
below.
if ((parameters.TryGetValue(SilentKey, out var silent) && (silent.ToString() == "true" || silent.ToString() == "1")) || (IsInForeground() && (!(!parameters.ContainsKey(ChannelIdKey) && parameters.TryGetValue(PriorityKey, out var imp) && ($"{imp}" == "high" || $"{imp}" == "max")) || (!parameters.ContainsKey(PriorityKey) && !parameters.ContainsKey(ChannelIdKey) && PushNotificationManager.DefaultNotificationChannelImportance != NotificationImportance.High && PushNotificationManager.DefaultNotificationChannelImportance != NotificationImportance.Max))))
{
return;
}
For easier reading, I split the condition to multiple parts.
var isSilent = parameters.TryGetValue(SilentKey, out var silent) && (silent.ToString() == "true" || silent.ToString() == "1");
var channelUndefined = !parameters.ContainsKey(ChannelIdKey);
var priorityUndefined = !parameters.ContainsKey(PriorityKey);
var priorityAboveHigh = parameters.TryGetValue(PriorityKey, out var imp) && ($"{imp}" == "high" || $"{imp}" == "max");
var defaultImportanceBelowHigh = PushNotificationManager.DefaultNotificationChannelImportance != NotificationImportance.High && PushNotificationManager.DefaultNotificationChannelImportance != NotificationImportance.Max;
if (isSilent || (IsInForeground() && (!(channelUndefined && priorityAboveHigh) || (priorityUndefined && channelUndefined && defaultImportanceBelowHigh))))
{
return;
}
In my case, the result would be
if (false || (true && (!(true && false) || (true && true && false))))
{
return;
}
and therefore exits the method.
I am not sure is this behaviour a mistake or intended, so I didn't create
a pull request for this.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#149>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AATOAJYHGNRCGQO66ITSTL3RYRT6PANCNFSM4OJFFF7A>
.
|
Below is how I initialize, it is run in
The issue is that setting With notification contains only message and With notification contains |
@kpto We had the same problem. This behaviour can be suppressed by making an entry in the AndroidManifest. AndroidManifest.xml MainApplication.cs |
When the notification payload doesn't include
priority
orchannel_id
. I expect that the notification will be shown if I set theDefaultNotificationChannelImportance
to high or above, but it doesn't.After reading the source code, I suspect that the first if block in
OnReceived
ofDefaultPushNotificationHandler
is wrongly written, as shown below.For easier reading, I split the condition to multiple parts.
In my case, the result would be
and therefore exits the method.
I am not sure is this behaviour a mistake or intended, so I didn't create a pull request for this.
The text was updated successfully, but these errors were encountered: