繁体   English   中英

本地通知实施

[英]Local notifications implementation

我正在尝试使用Xamarin.Forms为我的android应用程序实现Local通知(带有单击事件和HeadUP通知)。 我已经按照Microsoft的本地通知文档进行操作,但是我不知道如何实现它。任何人都可以分享任何工作示例。

谢谢。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM