internal void Update(
            Context context, Kind kind, NotifyEvents notifyEvents, string contentFormat, params object[] args)
        {
            // Sometimes exception messages contain curly braces, which confuses string.Format
            this.ContentText = args.Length > 0 ? string.Format(CurrentCulture, contentFormat, args) : contentFormat;
            var showPopup = (int)kind >= (int)notifyEvents;

            if (showPopup)
            {
                #pragma warning disable CS0618                                                                      // Type or member is obsolete
                using (var builder = new Android.App.Notification.Builder(context))
                                                                                     #pragma warning restore CS0618 // Type or member is obsolete
                    using (var intent = new Intent(context, this.activityType))
                        using (var style = new Android.App.Notification.BigTextStyle())
                        {
                            // This is necessary so that the intent object is going to be interpreted as a new intent rather than
                            // an update to an existing intent.
                            intent.SetAction(this.id.ToString());

                            this.addArguments(intent);
                            builder
                            .SetSmallIcon(Resource.Drawable.ic_stat_name)
                            .SetContentTitle(this.title)
                            .SetContentText(this.ContentText)
                            .SetContentIntent(PendingIntent.GetActivity(context, 0, intent, 0))
                            .SetStyle(style.BigText(this.ContentText))
                            .SetAutoCancel(true);
                            SetLights(builder, kind);
                            this.manager.Notify(this.id, builder.Build());
                        }
            }

            Info("Notification{0}: {1}", showPopup ? " (shown in popup)" : string.Empty, this.ContentText);
        }
Beispiel #2
0
        public void Send(string title, string message)
        {
            //Get Activity
            MainActivity activity = Forms.Context as MainActivity;
            var          context  = activity.Window.Context;

            // Instantiate the builder and set notification elements:

            Android.App.Notification.Builder notificationBuilder = new Android.App.Notification.Builder(context)
                                                                   .SetSmallIcon(Resource.Drawable.icon)
                                                                   .SetContentTitle(title)
                                                                   .SetContentText(message)
                                                                   .SetDefaults(NotificationDefaults.Sound);

            // Build the notification:
            Android.App.Notification notification = notificationBuilder.Build();

            // Turn on vibrate:
            notification.Defaults |= NotificationDefaults.Vibrate;

            //Auto cancel will remove the notification once the user touches it
            notification.Flags = NotificationFlags.AutoCancel;

            // Get the notification manager:
            NotificationManager notificationManager =
                context.GetSystemService(Context.NotificationService) as NotificationManager;

            // Publish the notification:
            notificationManager.Notify(NOTIFICATION_ID, notification);
        }
        //public void TimerMethod()
        //{
        //    TimerExampleState s = new TimerExampleState();

        //    // Create the delegate that invokes methods for the timer.
        //    TimerCallback timerDelegate = new TimerCallback(LaunchNotification);

        //    // Create a timer that waits one second, then invokes every second.
        //    Timer timer = new Timer(timerDelegate, s, 1000, 1000);

        //    // Keep a handle to the timer, so it can be disposed.
        //    s.tmr = timer;

        //    // The main thread does nothing until the timer is disposed.
        //    while (s.tmr != null)
        //        Thread.Sleep(0);
        //    Console.WriteLine("Timer example done.");
        //}

        private void LaunchNotification(string title, string message)
        {
            // Get the notifications manager:
            NotificationManager notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;

            // Instantiate the notification builder:
            Android.App.Notification.Builder builder = new Android.App.Notification.Builder(this)
                                                       .SetContentTitle(title)
                                                       .SetContentText(message)
                                                       .SetSmallIcon(Resource.Drawable.ic_notification)
                                                       .SetAutoCancel(true);


            // Build the notification:
            Android.App.Notification notification = builder.Build();

            notification.Defaults |= NotificationDefaults.Sound;

            // Notification ID used for all notifications in this app.
            // Reusing the notification ID prevents the creation of
            // numerous different notifications as the user experiments
            // with different notification settings -- each launch reuses
            // and updates the same notification.
            const int notificationId = 1;

            // Launch notification:
            notificationManager.Notify(notificationId, notification);
        }
Beispiel #4
0
        public void Notify(Notification message)
        {
            Intent intent = new Intent(Context, typeof(MainActivity));

            intent.PutExtra("NOTIFICATION_URL", message.Url);
            PendingIntent pendingIntent =
                PendingIntent.GetActivity(Context, PENDING_REQUEST, intent, PendingIntentFlags.OneShot);


#pragma warning disable CS0618 // Type or member is obsolete
            Android.App.Notification notification = new Android.App.Notification.Builder(Context)
                                                    .SetContentIntent(pendingIntent)
                                                    .SetAutoCancel(true)
                                                    .SetContentTitle("Alert")
                                                    .SetContentText(message.Title)
                                                    .SetVibrate(new long[] { 1000, 1000 })
                                                    .SetSound(Settings.System.DefaultNotificationUri)
#pragma warning restore CS0618 // Type or member is obsolete
                                                    .SetSmallIcon(Resource.Drawable.bell)
                                                    .SetLargeIcon(((BitmapDrawable)Context.GetDrawable(Resource.Drawable.icon)).Bitmap)
                                                    .Build();

            NotificationManager notificationManager =
                Context.GetSystemService(Context.NotificationService) as NotificationManager;

            notificationManager.Notify(NOTIFICATION_ID, notification);
        }
        //ImageSource repeaton = ImageSource.FromFile("ic_repeat_grey600_36dp.png");
        //ImageSource repeatoff = ImageSource.FromFile("ic_repeat_off_grey600_36dp.png");

        public static Notification Get(string name, string author, string cover, bool i, bool r)
        {
            int           icon       = i ? VkMusic2.Droid.Resource.Drawable.ic_pause_grey600_36dp : VkMusic2.Droid.Resource.Drawable.ic_play_grey600_36dp;
            int           repeaticon = r ? VkMusic2.Droid.Resource.Drawable.ic_repeat_off_grey600_36dp : VkMusic2.Droid.Resource.Drawable.ic_repeat_grey600_36dp;
            PendingIntent playm      = i ? PIPause : PIPlay;
            PendingIntent repeatm    = r ? PIRepeatOff : PIRepeatOn;
            var           builder    = new Android.App.Notification.Builder(Xamarin.Forms.Forms.Context)
                                       .SetStyle(new Notification.MediaStyle()
                                                 .SetShowActionsInCompactView(
                                                     new[] { 1, 2, 3 }))
                                       .AddAction(new Notification.Action(repeaticon, "3", repeatm))
                                       .AddAction(new Notification.Action(VkMusic2.Droid.Resource.Drawable.ic_skip_previous_grey600_36dp, "1", PIPrev))
                                       .AddAction(new Notification.Action(icon, "0", playm))
                                       .AddAction(new Notification.Action(VkMusic2.Droid.Resource.Drawable.ic_skip_next_grey600_36dp, "2", PINext))
                                       .AddAction(new Notification.Action(VkMusic2.Droid.Resource.Drawable.ic_close_grey600_36dp, "2", PIClose))
                                       .SetContentTitle(name)
                                       .SetContentText(author)
                                       .SetSmallIcon(VkMusic2.Droid.Resource.Mipmap.ic_launcher)
                                       .SetVisibility(NotificationVisibility.Public)
                                       .SetShowWhen(false)
                                       .SetOngoing(true)
                                       .SetAutoCancel(true);



            return(builder.Build());
        }
Beispiel #6
0
        public void Send(string title, string message, ActivityType activityType, int notificationID)
        {
            MainActivity activity = Forms.Context as MainActivity;
            var          context  = activity.Window.Context;

            // Setup an intent for SecondActivity:
            Intent secondIntent = new Intent(context, typeof(MainActivity));

            // Pass some information to SecondActivity:
            secondIntent.PutExtra("action", activityType.ToString());

            // Create a task stack builder to manage the back stack:
            TaskStackBuilder stackBuilder = TaskStackBuilder.Create(context);

            // Add all parents of SecondActivity to the stack:
            stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity)));

            // Push the intent that starts SecondActivity onto the stack:
            stackBuilder.AddNextIntent(secondIntent);

            // Obtain the PendingIntent for launching the task constructed by stackbuilder. The
            // pending intent can be used only once (one shot):
            const int     pendingIntentId = 0;
            PendingIntent pendingIntent   =
                stackBuilder.GetPendingIntent(pendingIntentId, PendingIntentFlags.OneShot);

            // Instantiate the builder and set notification elements, including the pending intent:
            Android.App.Notification.Builder builder = new Android.App.Notification.Builder(context)
                                                       .SetContentIntent(pendingIntent)
                                                       .SetContentTitle(title)
                                                       .SetContentText(message)
                                                       .SetSmallIcon(Resource.Drawable.icon)
                                                       .SetDefaults(NotificationDefaults.Sound);

            // Build the notification:
            Android.App.Notification notification = builder.Build();

            // Turn on vibrate:
            notification.Defaults |= NotificationDefaults.Vibrate;

            // Get the notification manager:
            NotificationManager notificationManager =
                context.GetSystemService(Context.NotificationService) as NotificationManager;

            // Publish the notification:
            const int notificationId = 0;

            notificationManager.Notify(notificationId, notification);
        }
        public override StartCommandResult OnStartCommand(Intent intent, [GeneratedEnum] StartCommandFlags flags, int startId)
        {
            var notification = new Android.App.Notification.Builder(this)
                               .SetContentTitle(Resources.GetString(Resource.String.app_name))
                               .SetContentText("ビーコン領域を監視中")
                               .SetSmallIcon(Resource.Mipmap.appicon)
                               .SetChannelId(NotificationUtil.SERVICE_NOTIFICATION_CHANNEL_ID)
                               .SetOngoing(true)
                               .Build();

            StartForeground(1, notification);

            _beaconManager = BeaconManager.GetInstanceForApplication(this.ApplicationContext);
            _beaconManager.Bind(this);

            return(base.OnStartCommand(intent, flags, startId));
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        private static void SetLights(Android.App.Notification.Builder builder, Kind kind)
        {
            switch (kind)
            {
            case Kind.Error:
                    #pragma warning disable CS0618 // Type or member is obsolete
                builder.SetLights(Color.ParseColor("red"), 2000, 2000);
                    #pragma warning restore CS0618 // Type or member is obsolete
                break;

            case Kind.Warning:
                    #pragma warning disable CS0618 // Type or member is obsolete
                builder.SetLights(Color.ParseColor("yellow"), 2000, 2000);
                    #pragma warning restore CS0618 // Type or member is obsolete
                break;
            }
        }
Beispiel #9
0
        public override void OnReceive(Context context, Intent intent)
        {
            var extra   = intent.GetStringExtra(NotificationKey);
            var id      = intent.GetStringExtra(NotificationBuilder.NotificationId);
            var options = DeserializeNotification(extra);

            if (!string.IsNullOrEmpty(options.AndroidOptions.HexColour) && options.AndroidOptions.HexColour.Substring(0, 1) != "#")
            {
                options.AndroidOptions.HexColour = "#" + options.AndroidOptions.HexColour;
            }

            // Show Notification
            Android.App.Notification.Builder builder = new Android.App.Notification.Builder(Application.Context)
                                                       .SetContentTitle(options.AndroidOptions.DebugShowIdInTitle ? "[" + id + "] " + options.Title : options.Title)
                                                       .SetContentText(options.Description)
                                                       .SetSmallIcon(options.AndroidOptions.SmallDrawableIcon.Value) // Must have small icon to display
                                                       .SetPriority((int)NotificationPriority.High)                  // Must be set to High to get Heads-up notification
                                                       .SetDefaults(NotificationDefaults.All)                        // Must also include vibrate to get Heads-up notification
                                                       .SetAutoCancel(true)
                                                       .SetColor(Color.ParseColor(options.AndroidOptions.HexColour));

            if (options.AndroidOptions.ForceOpenAppOnNotificationTap)
            {
                var clickIntent = new Intent(NotificationBuilder.OnClickIntent);
                clickIntent.PutExtra(NotificationBuilder.NotificationId, int.Parse(id));
                clickIntent.PutExtra(NotificationBuilder.NotificationForceOpenApp, options.AndroidOptions.ForceOpenAppOnNotificationTap);
                var pendingClickIntent = PendingIntent.GetBroadcast(Application.Context, (NotificationBuilder.StartId + int.Parse(id)), clickIntent, 0);
                builder.SetContentIntent(pendingClickIntent);
            }

            // Notification Channel
            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
            {
                var notificationChannelId = NotificationBuilder.GetOrCreateChannel(options.AndroidOptions.ChannelOptions);
                if (!string.IsNullOrEmpty(notificationChannelId))
                {
                    builder.SetChannelId(notificationChannelId);
                }
            }

            Android.App.Notification notification = builder.Build();

            NotificationManager notificationManager = Application.Context.GetSystemService(Context.NotificationService) as NotificationManager;

            notificationManager.Notify(Convert.ToInt32(id), notification);
        }
        /// <summary>
        /// Shows the notification in th notification tray.
        /// </summary>
        /// <param name="message">The notification message to show.</param>
        private void ShowNotification(string message)
        {
            // If the application is active
            var instance = Xamarin.Forms.Application.Current as App;

            if (instance?.IsActive == true)
            {
                // Show a message
                Xamarin.Forms.Device.BeginInvokeOnMainThread(
                    () =>
                    App.DisplayAlert(
                        Properties.Localization.NotificationDialogTitle,
                        message,
                        Properties.Localization.DialogDismiss));
                return;
            }

            // Launch the application on notification click
            var intent = new Intent(this, typeof(MainActivity));

            intent.SetAction(Intent.ActionView);
            intent.PutExtra(MainActivity.StartView, MainActivity.NotificationsView);
            intent.AddFlags(ActivityFlags.ClearTop);
            var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);

            // Create a new notification
            var sound = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
            var notificationBuilder =
                new Android.App.Notification.Builder(this).SetSmallIcon(Resource.Drawable.icon)
                .SetContentTitle("Xalapa Limpia")
                .SetContentText(message)
                .SetSound(sound)
                .SetAutoCancel(true)
                .SetContentIntent(pendingIntent);

            // Show notification in the notification tray
            var notificationManager = (NotificationManager)this.GetSystemService(Context.NotificationService);

            notificationManager.Notify(0, notificationBuilder.Build());
        }
Beispiel #11
0
        public override void OnReceive(Context context, Intent intent)
        {
            var extra   = intent.GetStringExtra(NotificationKey);
            var id      = intent.GetStringExtra(NotificationBuilder.NotificationId);
            var options = DeserializeNotification(extra);

            // Show Notification
            Android.App.Notification.Builder builder = new Android.App.Notification.Builder(Application.Context)
                                                       .SetContentTitle(options.Title)
                                                       .SetContentText(options.Description)
                                                       .SetSmallIcon(options.AndroidOptions.SmallDrawableIcon.Value) // Must have small icon to display
                                                       .SetPriority((int)NotificationPriority.High)                  // Must be set to High to get Heads-up notification
                                                       .SetDefaults(NotificationDefaults.All)                        // Must also include vibrate to get Heads-up notification
                                                       .SetAutoCancel(true);

            Android.App.Notification notification = builder.Build();

            NotificationManager notificationManager =
                Application.Context.GetSystemService(Context.NotificationService) as NotificationManager;

            notificationManager.Notify(Convert.ToInt32(id), notification);
        }
        public override void OnCreate()
        {
            base.OnCreate();
            socket.On("notification", data =>
            {
                var e = JsonConvert.DeserializeObject <List <Device> >(data.ToString());
                Android.App.Notification.Builder builder = new Android.App.Notification.Builder(this)
                                                           .SetContentTitle("Turned On")
                                                           .SetContentText(e[0].name + " " + e[0].value + " W")
                                                           .SetDefaults(NotificationDefaults.Sound)
                                                           .SetSmallIcon(e[0].icon_id);

                // Build the notification:
                Android.App.Notification notification = builder.Build();

                // Get the notification manager:
                Android.App.NotificationManager notificationManager =
                    GetSystemService(Context.NotificationService) as NotificationManager;

                // Publish the notification:
                const int notificationId = 0;
                notificationManager.Notify(notificationId, notification);
            });
        }
Beispiel #13
0
        private void ShowNotification(Models.Notification _Notification)
        {
            Intent HClickIntent = new Intent(_context, (typeof(MainActivity)));

            HClickIntent.PutExtra("BY_EVENT", (_Notification.EVENT_IDENT != -1));
            if (_Notification.EVENT_IDENT != -1)
            {
                HClickIntent.PutExtra("EVENT_IDENT", _Notification.EVENT_IDENT);
            }
            else
            {
                if (_Notification.EVENT_DATE != "")
                {
                    HClickIntent.PutExtra("START_DATE", _Notification.EVENT_DATE);
                }
            }

            // Wir werden nicht mehr als 10000 notifications haben
            int           HPendingIntentIdPre = _Notification.IDENT + 10000;
            PendingIntent HPendingIntent      = PendingIntent.GetActivity(_context, HPendingIntentIdPre, HClickIntent, PendingIntentFlags.OneShot);


            Android.App.Notification.Builder HBuilder = new Android.App.Notification.Builder(_context)
                                                        .SetContentIntent(HPendingIntent)
                                                        .SetContentTitle(_Notification.CAPTION)
                                                        .SetContentText(_Notification.DESCRIPTION)
                                                        .SetDefaults(NotificationDefaults.Vibrate)
                                                        .SetAutoCancel(true)
                                                        .SetSmallIcon(Resource.Drawable.icon);

            Android.App.Notification HNotification = HBuilder.Build();

            NotificationManager HNotificationManager = _context.GetSystemService(MainActivity.NotificationService) as NotificationManager;

            HNotificationManager.Notify(_Notification.IDENT, HNotification);
        }
        public override Task Send(Notification notification)
        {
            if (notification.Id == null)
            {
                Services.Repository.CurrentScheduleId++;
                notification.Id = Services.Repository.CurrentScheduleId;
            }

            if (notification.IsScheduled)
            {
                var triggerMs = this.GetEpochMills(notification.SendTime);
                var pending   = notification.ToPendingIntent(notification.Id.Value);

                this.alarmManager.Set(
                    AlarmType.RtcWakeup,
                    Convert.ToInt64(triggerMs),
                    pending
                    );
                Services.Repository.Insert(notification);
            }
            else
            {
                var launchIntent = Application.Context.PackageManager.GetLaunchIntentForPackage(Application.Context.PackageName);
                launchIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
                foreach (var pair in notification.Metadata)
                {
                    launchIntent.PutExtra(pair.Key, pair.Value);
                }

                var builder = new Android.App.Notification.Builder(Application.Context)
                              .SetAutoCancel(true)
                              .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                              .SetContentTitle(notification.Title)
                              .SetContentText(notification.Message)
                              .SetSmallIcon(AppIconResourceId)
                              .SetPriority(priority.HasValue ? priority.Value : NotificationCompat.PriorityMax)
                              .SetContentIntent(TaskStackBuilder
                                                .Create(Application.Context)
                                                .AddNextIntent(launchIntent)
                                                .GetPendingIntent(notification.Id.Value, PendingIntentFlags.OneShot)
                                                );

                if (notification.Vibrate)
                {
                    builder.SetVibrate(new long[] { 500, 500 });
                }

                if (notification.Sound != null)
                {
                    if (!notification.Sound.Contains("://"))
                    {
                        notification.Sound = $"{ContentResolver.SchemeAndroidResource}://{Application.Context.PackageName}/raw/{notification.Sound}";
                    }
                    var uri = Android.Net.Uri.Parse(notification.Sound);
                    builder.SetSound(uri);
                }
                var not = builder.Build();
                NotificationManagerCompat
                .From(Application.Context)
                .Notify(notification.Id.Value, not);
            }
            return(Task.CompletedTask);
        }
Beispiel #15
0
        public override void OnReceive(Context context, Intent intent)
        {
            try
            {
                Android.Net.Uri alert = RingtoneManager.GetDefaultUri(RingtoneType.Alarm);
                alert = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
                alert = RingtoneManager.GetDefaultUri(RingtoneType.Ringtone);

                // Toast.MakeText(context, "Received intent!", ToastLength.Long).Show();
                var             matakuliah = intent.GetStringExtra("matakuliah");
                var             waktu      = intent.GetStringExtra("waktu");
                var             jadwalId   = Convert.ToInt32(intent.GetStringExtra("jadwalId"));
                Android.Net.Uri soundUri   = Android.Net.Uri.Parse("android.resource://" + "com.ocph23.stimik.simak" + "/raw/alarm");

                if (Build.VERSION.SdkInt < BuildVersionCodes.O)
                {
                    intent.AddFlags(ActivityFlags.ClearTop);
                    var pendingIntent       = PendingIntent.GetActivity(context, 0, intent, PendingIntentFlags.OneShot);
                    var notificationBuilder = new Notification.Builder(context)
                                              .SetContentTitle(waktu)
                                              .SetSmallIcon(Resource.Drawable.Logostimik)
                                              .SetContentText(matakuliah)
                                              .SetAutoCancel(true)
                                              .SetSound(soundUri)
                                              .SetContentIntent(pendingIntent)
                                              .SetPriority((int)Notification.PriorityHigh);
                    var notificationManager = NotificationManager.FromContext(context);
                    notificationManager.Notify(jadwalId, notificationBuilder.Build());
                }
                else
                {
                    intent.AddFlags(ActivityFlags.MultipleTask);
                    var pendingIntent = PendingIntent.GetActivity(context, jadwalId, intent, PendingIntentFlags.OneShot);

                    var notificationBuilder = new Android.App.Notification.Builder(context)
                                              .SetAutoCancel(true)
                                              .SetContentTitle(waktu)
                                              .SetSmallIcon(Resource.Drawable.Logostimik)
                                              .SetContentText(matakuliah)
                                              .SetAutoCancel(true)
                                              .SetSound(soundUri)
                                              .SetVibrate(new long[] { 1000, 1000, 1000 })
                                              .SetContentIntent(pendingIntent)
                                              .SetChannelId(jadwalId.ToString())
                                              .SetPriority((int)Notification.PriorityMax);


                    notificationBuilder.SetSound(Android.Net.Uri.Parse("android.resource://" + context.PackageName + "/" + Resource.Raw.atschool));//Here is FILE_NAME is the name of file that you want to play


                    var channel = new NotificationChannel(jadwalId.ToString(), matakuliah, NotificationImportance.High)
                    {
                        Description = waktu
                    };

                    var notificationManager = (NotificationManager)context.GetSystemService(Context.NotificationService);
                    notificationManager.CreateNotificationChannel(channel);
                    MediaPlayer mp = MediaPlayer.Create(context, Resource.Raw.schoolringing);
                    if (!mp.IsPlaying)
                    {
                        mp.Start();
                    }
                    notificationManager.Notify(jadwalId, notificationBuilder.Build());
                }
            }
            catch (Exception)
            {
//                throw;
            }
        }
Beispiel #16
0
        public INotificationResult Notify(Activity activity, INotificationOptions options)
        {
            var notificationId = _count;
            var id             = _count.ToString();

            _count++;

            Intent dismissIntent = new Intent(DismissedClickIntent);

            dismissIntent.PutExtra(NotificationId, notificationId);

            PendingIntent pendingDismissIntent = PendingIntent.GetBroadcast(activity.ApplicationContext, 123, dismissIntent, 0);

            Intent clickIntent = new Intent(OnClickIntent);

            clickIntent.PutExtra(NotificationId, notificationId);

            // Add custom args
            if (options.CustomArgs != null)
            {
                foreach (var arg in options.CustomArgs)
                {
                    clickIntent.PutExtra(arg.Key, arg.Value);
                }
            }

            PendingIntent pendingClickIntent = PendingIntent.GetBroadcast(activity.ApplicationContext, 123, clickIntent, 0);

            int smallIcon;

            if (options.AndroidOptions.SmallDrawableIcon.HasValue)
            {
                smallIcon = options.AndroidOptions.SmallDrawableIcon.Value;
            }
            else if (_androidOptions.SmallIconDrawable.HasValue)
            {
                smallIcon = _androidOptions.SmallIconDrawable.Value;
            }
            else
            {
                smallIcon = Android.Resource.Drawable.IcDialogInfo; // As last resort
            }
            Android.App.Notification.Builder builder = new Android.App.Notification.Builder(activity)
                                                       .SetContentTitle(options.Title)
                                                       .SetContentText(options.Description)
                                                       .SetSmallIcon(smallIcon)                     // Must have small icon to display
                                                       .SetPriority((int)NotificationPriority.High) // Must be set to High to get Heads-up notification
                                                       .SetDefaults(NotificationDefaults.All)       // Must also include vibrate to get Heads-up notification
                                                       .SetAutoCancel(true)                         // To allow click event to trigger delete Intent
                                                       .SetContentIntent(pendingClickIntent)        // Must have Intent to accept the click
                                                       .SetDeleteIntent(pendingDismissIntent);

            Android.App.Notification notification = builder.Build();

            NotificationManager notificationManager =
                activity.GetSystemService(Context.NotificationService) as NotificationManager;

            notificationManager.Notify(notificationId, notification);

            var timer = new Timer(x => TimerFinished(id), null, TimeSpan.FromSeconds(7), TimeSpan.FromSeconds(100));

            var resetEvent = new ManualResetEvent(false);

            ResetEvent.Add(id, resetEvent);

            resetEvent.WaitOne(); // Wait for a result

            var notificationResult = EventResult[id];

            if (!options.IsClickable && notificationResult.Action == NotificationAction.Clicked)
            {
                notificationResult.Action = NotificationAction.Dismissed;
            }

            EventResult.Remove(id);
            ResetEvent.Remove(id);

            // Dispose of Intents and Timer
            pendingClickIntent.Cancel();
            pendingDismissIntent.Cancel();
            timer.Dispose();

            return(notificationResult);
        }
        public INotificationResult Notify(Activity activity, INotificationOptions options)
        {
            INotificationResult notificationResult = null;

            if (options != null)
            {
                var notificationId = 0;
                var id             = "";
                lock (_lock)
                {
                    notificationId = _count;
                    id             = _count.ToString();
                    _count++;
                }

                int smallIcon;

                if (options.AndroidOptions.SmallDrawableIcon.HasValue)
                {
                    smallIcon = options.AndroidOptions.SmallDrawableIcon.Value;
                }
                else if (_androidOptions.SmallIconDrawable.HasValue)
                {
                    smallIcon = _androidOptions.SmallIconDrawable.Value;
                }
                else
                {
                    smallIcon = Android.Resource.Drawable.IcDialogInfo; // As last resort
                }
                if (options.DelayUntil.HasValue)
                {
                    options.AndroidOptions.SmallDrawableIcon = smallIcon;
                    ScheduleNotification(id, options);
                    return(new NotificationResult()
                    {
                        Action = NotificationAction.NotApplicable, Id = notificationId
                    });
                }

                // Show Notification Right Now
                var dismissIntent = new Intent(DismissedClickIntent);
                dismissIntent.PutExtra(NotificationId, notificationId);

                var pendingDismissIntent = PendingIntent.GetBroadcast(Application.Context, (StartId + notificationId), dismissIntent, 0);

                var clickIntent = new Intent(OnClickIntent);
                clickIntent.PutExtra(NotificationId, notificationId);
                clickIntent.PutExtra(NotificationForceOpenApp, options.AndroidOptions.ForceOpenAppOnNotificationTap);

                // Add custom args
                if (options.CustomArgs != null)
                {
                    foreach (var arg in options.CustomArgs)
                    {
                        clickIntent.PutExtra(arg.Key, arg.Value);
                    }
                }

                var pendingClickIntent = PendingIntent.GetBroadcast(Application.Context, (StartId + notificationId), clickIntent, 0);

                if (!string.IsNullOrEmpty(options.AndroidOptions.HexColor) && options.AndroidOptions.HexColor.Substring(0, 1) != "#")
                {
                    options.AndroidOptions.HexColor = "#" + options.AndroidOptions.HexColor;
                }

                Android.App.Notification.Builder builder = new Android.App.Notification.Builder(Application.Context)
                                                           .SetContentTitle(options.Title)
                                                           .SetContentText(options.Description)
                                                           .SetSmallIcon(smallIcon)                     // Must have small icon to display
                                                           .SetPriority((int)NotificationPriority.High) // Must be set to High to get Heads-up notification
                                                           .SetDefaults(NotificationDefaults.All)       // Must also include vibrate to get Heads-up notification
                                                           .SetAutoCancel(true)                         // To allow click event to trigger delete Intent
                                                           .SetContentIntent(pendingClickIntent)        // Must have Intent to accept the click
                                                           .SetDeleteIntent(pendingDismissIntent)
                                                           .SetColor(Color.ParseColor(options.AndroidOptions.HexColor));

                try
                {
                    // Notification Channel
                    if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
                    {
                        var notificationChannelId = GetOrCreateChannel(options.AndroidOptions.ChannelOptions);
                        if (!string.IsNullOrEmpty(notificationChannelId))
                        {
                            builder.SetChannelId(notificationChannelId);
                        }
                    }
                }
                catch { }
                // System.MissingMethodException: Method 'Android.App.Notification/Builder.SetChannelId' not found.
                // I know this is bad, but I can't replicate it on any version, and many people are experiencing it.

                Android.App.Notification notification = builder.Build();

                NotificationManager notificationManager = Application.Context.GetSystemService(Context.NotificationService) as NotificationManager;

                notificationManager.Notify(notificationId, notification);

                if (options.DelayUntil.HasValue)
                {
                    return(new NotificationResult()
                    {
                        Action = NotificationAction.NotApplicable, Id = notificationId
                    });
                }

                var timer = new Timer(x => TimerFinished(id, options.ClearFromHistory, options.AllowTapInNotificationCenter), null, TimeSpan.FromSeconds(7), TimeSpan.FromMilliseconds(-1));

                var resetEvent = new ManualResetEvent(false);
                ResetEvent.Add(id, resetEvent);

                resetEvent.WaitOne(); // Wait for a result

                notificationResult = EventResult[id];

                if (!options.IsClickable && notificationResult.Action == NotificationAction.Clicked)
                {
                    notificationResult.Action = NotificationAction.Dismissed;
                    notificationResult.Id     = notificationId;
                }

                if (EventResult.ContainsKey(id))
                {
                    EventResult.Remove(id);
                }
                if (ResetEvent.ContainsKey(id))
                {
                    ResetEvent.Remove(id);
                }

                // Dispose of Intents and Timer
                pendingClickIntent.Cancel();
                pendingDismissIntent.Cancel();
                timer.Dispose();
            }
            return(notificationResult);
        }