예제 #1
0
        public static void SendNotification(Context?context, String?title, String?content, int?icon, Intent?intent)
        {
            NotificationUtils notificationUtils = new NotificationUtils(context);
            Notification      notification;

            //26
            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                notificationUtils.CreateNotificationChannel();
                notification = notificationUtils.GetChannelNotification(title, content, icon ?? 0, intent).Build();
            }
            else
            {
                notification = notificationUtils.GetNotification_25(title, content, icon ?? 0, intent).Build();
            }
            notificationUtils.GetManager()
            .Notify(new Java.Util.Random()
                    .NextInt(10000), notification);
        }
예제 #2
0
        public static Notification CreateNotification(Context?context, String?title, String?content, int?icon, Intent?intent)
        {
            NotificationUtils notificationUtils = new NotificationUtils(context);
            Notification      notification;

            //26
            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                notificationUtils.CreateNotificationChannel();
                notification = notificationUtils.GetChannelNotification(title, content, icon ?? 0, intent).Build();
            }
            //else if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            //{
            //    // importance: 通知重要性
            //    // IMPORTANCE_HIGH:紧急级别(发出通知声音并显示为提示通知)
            //    // IMPORTANCE_DEFAULT:高级别(发出通知声音并且通知栏有通知)
            //    // IMPORTANCE_LOW:中等级别(没有通知声音但通知栏有通知)
            //    // IMPORTANCE_MIN:低级别(没有通知声音也不会出现在状态栏)
            //    var channel = new NotificationChannel(channelId, channelName, NotificationImportance.Low);

            //    //是否绕过请勿打扰模式
            //    channel.CanBypassDnd();

            //    //设置可绕过请勿打扰模式
            //    channel.SetBypassDnd(true);

            //    //锁屏显示通知
            //    channel.LockscreenVisibility = NotificationVisibility.Secret;

            //    //桌面launcher的消息角标
            //    channel.CanShowBadge();

            //    notificationManager.CreateNotificationChannel(channel);
            //}
            else
            {
                notification = notificationUtils.GetNotification_25(title, content, icon ?? 0, intent).Build();
            }
            return(notification);
        }