public Builder GetBuilder(Context context, ChannelId channelId)
        {
            Builder builder = new Builder(context);

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                Channel channel = Channels[(int)channelId];

                if (channel.NotificationChannel == null)
                {
                    // Create a NotificationChannel
                    NotificationChannel notificationChannel = new NotificationChannel(channel.ChannelId, channel.ChannelName, channel.Importance);
                    notificationChannel.Description = " ";
                    notificationChannel.EnableLights(channel.Lights);
                    notificationChannel.EnableVibration(channel.Vibration);
                    notificationChannel.SetBypassDnd(channel.DoNotDisturb);
                    notificationChannel.LockscreenVisibility = channel.Visibility;

                    // Register the new NotificationChannel
                    NotificationManagerCompat notificationManager = GetManager(context);
                    notificationManager.CreateNotificationChannel(notificationChannel);

                    channel.NotificationChannel = notificationChannel;
                }

                builder.SetChannelId(channel.ChannelId);
            }
            return(builder);
        }
Exemplo n.º 2
0
        public void NotifyVersion26(Context context, Android.Content.Res.Resources res, Android.App.NotificationManager manager)
        {
            string channelName = "Secondary Channel";
            var    importance  = NotificationImportance.High;
            var    channel     = new NotificationChannel(PRIMARY_CHANNEL, channelName, importance);

            var path           = Android.Net.Uri.Parse("android.resource://com.ufinix.uberdriver/" + Resource.Raw.alert);
            var audioattribute = new AudioAttributes.Builder()
                                 .SetContentType(AudioContentType.Sonification)
                                 .SetUsage(AudioUsageKind.Notification).Build();

            channel.EnableLights(true);
            channel.EnableLights(true);
            channel.SetSound(path, audioattribute);
            channel.LockscreenVisibility = NotificationVisibility.Public;

            manager.CreateNotificationChannel(channel);

            Intent intent = new Intent(context, typeof(MainActivity));

            intent.AddFlags(ActivityFlags.SingleTop);
            PendingIntent pendingIntent = PendingIntent.GetActivity(context, 0, intent, PendingIntentFlags.CancelCurrent);

            Notification.Builder builder = new Notification.Builder(context)
                                           .SetContentTitle("Uber Driver")
                                           .SetSmallIcon(Resource.Drawable.ic_location)
                                           .SetLargeIcon(BitmapFactory.DecodeResource(res, Resource.Drawable.iconimage))
                                           .SetContentText("You have a new trip request")
                                           .SetChannelId(PRIMARY_CHANNEL)
                                           .SetAutoCancel(true)
                                           .SetContentIntent(pendingIntent);

            manager.Notify(NOTIFY_ID, builder.Build());
        }
Exemplo n.º 3
0
        private void CreateChannel()
        {
            manager = (Android.App.NotificationManager)Application.Context.GetSystemService(Context.NotificationService);

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                var channelNameJava = new Java.Lang.String(channelName);
                var channel         = new NotificationChannel(channelId, channelNameJava, NotificationImportance.Default)
                {
                    Description = channelDescription
                };

                channel.SetSound(null, null);
                channel.EnableVibration(true);
                manager.CreateNotificationChannel(channel);
            }
        }