Код: Выделить всё
public override void OnMessageReceived(RemoteMessage message)
{
base.OnMessageReceived(message);
badgeNumber++;
var notification = message.GetNotification();
SendNotification(notification.Body, notification.Title, message.Data);
}
private void SendNotification(string messageBody, string title, IDictionary data)
{
var intent = new Intent(this, typeof(MainActivity));
intent.AddFlags(ActivityFlags.ClearTop);
intent.AddFlags(ActivityFlags.SingleTop);
foreach (var key in data.Keys)
{
var value = data[key];
intent.PutExtra(key, value);
}
var pendingIntent = PendingIntent.GetActivity(this,MainActivity.NotificationId, intent, PendingIntentFlags.OneShot | PendingIntentFlags.Immutable);
var notificationBuilder = new NotificationCompat.Builder(this, MainActivity.ChannelId)
.SetContentTitle(title)
.SetSmallIcon(Microsoft.Maui.Controls.Resource.Drawable.ic_notification)
.SetContentText(messageBody)
.SetChannelId(MainActivity.ChannelId)
.SetContentIntent(pendingIntent)
.SetAutoCancel(true)
.SetPriority((int)NotificationPriority.Max);
var notificationManager = NotificationManagerCompat.From(this);
notificationManager.Notify(MainActivity.NotificationId, notificationBuilder.Build());
}
Я пытался обернуть все в try-catch. Чтобы увидеть, может быть какая-то ошибка, но ошибок нет.
спасибо
Подробнее здесь: https://stackoverflow.com/questions/780 ... e-behavior