[英]Local notifications implementation
从Android官方文档来看,有两种设置重要性级别的方法。
第一个解决方案:(不起作用)
如果通知的优先级标记为“高”,“最大”或“全屏”,则会收到平视通知。
可能会触发抬头通知的条件示例包括:通知具有较高的优先级,并使用铃声或振动。使用物理设备进行尝试如下:
builder.SetVibrate(new long[0]);
builder.SetPriority((int)NotificationPriority.High);
不幸的是,上述解决方案不起作用。
第二个解决方案:(工作)
Xamarin Android中正确的方法可以设置Channel的属性。如果NotificationImportance.High
创建的Channel会显示抬头。您可以参考此官方示例 。 CreateNotificationChannel
如下所示修改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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.