0

i tried to setup an android notification channel for sending a message like this:

public override void OnCreate()
{
base.OnCreate();
var chanList = new List<NotificationChannelCompat>();
chanList.Add(new NotificationChannelCompat.Builder("DebugChannel", NotificationManagerCompat.ImportanceHigh) .SetName("DebugChannel").SetShowBadge(true).SetLightsEnabled(true).SetVibrationEnabled(true).Build());
    
NotificationManagerCompat.From(this).CreateNotificationChannelsCompat(chanList);
}

I also tried to register the "DebugChannel" without the compat libraries.

public override void OnCreate()
{
base.OnCreate();
if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
{
NotificationManager notMan = NotificationManager.FromContext(ApplicationContext);
NotificationChannel channel = new NotificationChannel("DebugChannel", "DebugChannel", NotificationImportance.High);
            channel.SetShowBadge(true);
            channel.EnableLights(true);
            channel.EnableVibration(true);
            notMan.CreateNotificationChannel(channel);
}
}

I also registered a topic named "all". Not shown in sample code. If i start the app an looking at the app infos i see the registered "DebugChannel". Now i tried to send a message to the my app, via the firebase admin sdk and set an non registered channelId:

  FirebaseAdmin.Messaging.Message message = new FirebaseAdmin.Messaging.Message
            {
                Notification = new Notification
                {
                    Body = body + "_Notification",
                    Title = title + "_Notification",
                },
                Data = new Dictionary<string, string>
                {
                    { "body", body +"_data"}, 
                    { "title", title +"_data"},
                    { "custom", "DataDictionary_custom" },
                    { "priority", "high" }, 
                },
                Android = new AndroidConfig
                {
                    Notification = new AndroidNotification
                    {
                        ChannelId = "InvalidChannelId", // 
                        Priority = NotificationPriority.HIGH,
                    },
                },
              

                Topic = "all",
            };
 var response = await FirebaseMessaging.DefaultInstance.SendAsync(message);

The question is, why is the OnMessageReceived:

    [Service(Exported = false)]
    [IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
    public class PNFirebaseMessagingService : FirebaseMessagingService
    {
        public override void OnMessageReceived(RemoteMessage message)
        {
            Console.WriteLine("OnMessageReceived");
        }
    {

method still called, although i send to a unknown/invalid channelid? I see the logcat message "OnMessageReceived". Is this the expected behavior or i do something wrong?
For testing, i tried to change the channelid to the valid value "DebugChannel" and disabled the channel in the android app info notifications setting. OnMessageReceived is still fired.
I tried an emulator with API 30 and 31. Same behavior.

Saftpresse99
  • 849
  • 7
  • 16
  • Hi Martin, not complete. Ok, if an invalid channel is specified, then the default channel ist used. But if i specify "DebugChannel" and disable this channel via settings app, why OnMessageReceived still fired. Only if i uncheck "All [myApp] notifications" OnMessageReceived is not called. – Saftpresse99 Jul 22 '22 at 11:11
  • I just noticed, that disable the "DebugChannel" via settings app works, if app is in background. In foreground disable has no effect. – Saftpresse99 Jul 22 '22 at 11:17

0 Answers0