0

I am working on a simple service in my app that also dispatches a notification to show the user, that the service is running. This DID work but stopped from one day to the other. I know that the code is beeing called right. I set a testing toast in within those lines and that is getting called every half second, so it should work but no notificaion shows up in the notification bar. Please have a look:

void DispatchNotificationThatServiceIsRunning()
        {
            _notificationIsLive = true;

            RemoteViews contentView = new RemoteViews(PackageName, Resource.Layout.Notification);
            contentView.SetTextViewText(Resource.Id.txt_crrentSong_notification, Activity_Player.txt_CurrentSong.Text);
            contentView.SetTextViewText(Resource.Id.txt_crrentSong__artist_notification, Activity_Player.txt_CurrentArtist.Text);

            notificationBuilder = new Notification.Builder(this);

            Task.Delay(_countDownFirstRound).ContinueWith(t =>
            {
                notificationBuilder
                .SetSmallIcon(Resource.Drawable.btn_icon_header)
                .SetCustomContentView(contentView);

                var notificationManager = (NotificationManager)GetSystemService(NotificationService);
                notificationManager.Notify(50, notificationBuilder.Build());

                DispatchNotificationThatServiceIsRunning();//This is for repeate every 1s.

                _countDownFirstRound = 50;

                // Click on notification, and return to app. Only works, because _2TimerRunning is set as : "LaunchMode = LaunchMode.SingleInstance"
                Intent notificationIntent = new Intent(this, typeof(Activity_Player));
                notificationIntent.SetAction(Intent.ActionMain);
                notificationIntent.AddCategory(Intent.CategoryLauncher);
                PendingIntent contentIntent = PendingIntent.GetActivity(this, 1, notificationIntent, PendingIntentFlags.UpdateCurrent);
                notificationBuilder.SetContentIntent(contentIntent);

            }, 

            TaskScheduler.FromCurrentSynchronizationContext());
        }

    }
innomotion media
  • 862
  • 11
  • 30

1 Answers1

2

Starting in Android 8.0 (API level 26), all notifications must be assigned to a channel. Refer this link..Create and Manage Notification Channels

Add this code before notificationManager.Notify(50, notificationBuilder.Build());

String channelId = "Default";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channel = new NotificationChannel(channelId, "Default channel", NotificationManager.IMPORTANCE_DEFAULT);
            notificationManager.createNotificationChannel(channel);
        }
Sachin Soma
  • 3,432
  • 2
  • 10
  • 18