Из официального документа Android , есть два способа установить уровень важности.
![enter image description here](https://i.stack.imgur.com/QxN2f.png)
Первое решение: (не работает)
Если приоритет уведомления помечен как Высокий, Макс или Полноэкранный режим, он получает уведомление об опережении.
Примеры условий, которые могут вызвать опрокидываниеуведомления включают в себя: Уведомление имеет высокий приоритет и использует рингтоны или вибрации. Используя физическое устройство, попробуйте выполнить следующее:
builder.SetVibrate(new long[0]);
builder.SetPriority((int)NotificationPriority.High);
Здесь аналогичное обсуждение Heads-up уведомления.
К сожалению, приведенное выше решение не работает.
Второе решение: (Работа)
Правильный путьв Xamarin Android можно установить свойство Channel . Если канал, созданный с помощью NotificationImportance.High
, может отображать заголовки. Вы можете сослаться на этот официальный пример . И изменить CreateNotificationChannel
метод следующим образом:
void CreateNotificationChannel()
{
if (Build.VERSION.SdkInt < BuildVersionCodes.O)
{
// Notification channels are new in API 26 (and not a part of the
// support library). There is no need to create a notification
// channel on older versions of Android.
return;
}
var name = Resources.GetString(Resource.String.channel_name);
var description = GetString(Resource.String.channel_description);
//Replace follow NotificationImportance.Default to NotificationImportance.High
var channel = new NotificationChannel(CHANNEL_ID, name, NotificationImportance.High)
{
Description = description
};
var notificationManager = (NotificationManager) GetSystemService(NotificationService);
notificationManager.CreateNotificationChannel(channel);
}
![enter image description here](https://i.stack.imgur.com/UHGrz.png)