Example #1
0
    public void startRinging()
    {
        if (ringtone != null)
        {
            return;
        }

        try
        {
            bool ring = true;

            if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.M)
            {
                NotificationManager nm         = (NotificationManager)MainActivity.Instance.GetSystemService(Context.NotificationService);
                InterruptionFilter  int_filter = nm.CurrentInterruptionFilter;
                if (int_filter != InterruptionFilter.Priority && int_filter != InterruptionFilter.All)
                {
                    ring = false;
                }
            }

            AudioManager am = (AudioManager)MainActivity.Instance.GetSystemService(Context.AudioService);
            if (am.RingerMode != RingerMode.Normal)
            {
                ring = false;
            }

            MainActivity.Instance.VolumeControlStream = Stream.Ring;
            if (ring)
            {
                Android.Net.Uri rt_url = RingtoneManager.GetDefaultUri(RingtoneType.Ringtone);
                AudioAttributes aa     = new AudioAttributes.Builder()
                                         .SetUsage(AudioUsageKind.NotificationRingtone)
                                         .Build();

                ringtone         = MediaPlayer.Create(MainActivity.Instance, rt_url, null, aa, 0);
                ringtone.Looping = true;
                ringtone.Start();
            }
        }catch (Exception e)
        {
            Logging.error("Exception occured in startRinging: " + e);
            ringtone = null;
        }
    }
Example #2
0
        public void Notifications()
        {
            try
            {
                var currentContext = Android.App.Application.Context;
                var alarmUri       = RingtoneManager.GetDefaultUri(RingtoneType.Alarm);
                Ringtone = RingtoneManager.GetRingtone(currentContext.ApplicationContext, alarmUri);
                Ringtone.Play();

                long[] pattern = { 0, 1500, 2000 };
                Vibrator = Vibrator.FromContext(currentContext);
                Vibrator.Vibrate(pattern, 0);
            }
            catch (Exception ex)
            {
                UserDialogs.Instance.Alert("Bład!\r\n\r\n" + ex.ToString(), "Błąd", "OK");
            }
        }
Example #3
0
        /// <summary>
        /// Sets the path to the ringtone. If the user did not set a sound then the default device ringtone is used.
        /// </summary>
        /// <returns></returns>
        private Android.Net.Uri getAlarmUri()
        {
            Android.Net.Uri alert = ringTonePath;

            if (alert == null)
            {
                alert = RingtoneManager.GetDefaultUri(RingtoneType.Alarm);
                if (alert == null)
                {
                    alert = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
                    if (alert == null)
                    {
                        alert = RingtoneManager.GetDefaultUri(RingtoneType.Ringtone);
                    }
                }
            }
            return(alert);
        }
Example #4
0
        void CreateNotification(string title, string description)
        {
            var notificationManager = GetSystemService(NotificationService) as NotificationManager;

            var uiIntent = new Intent(this, typeof(MainActivity));
            var builder  = new NotificationCompat.Builder(this);

            var notification = builder.SetContentIntent(PendingIntent.GetActivity(this, 0, uiIntent, 0))
                               .SetSmallIcon(Android.Resource.Drawable.SymActionEmail)
                               .SetTicker(title)
                               .SetContentTitle(title)
                               .SetContentText(description)
                               .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                               .SetAutoCancel(true).Build();

            //Show the notification
            notificationManager?.Notify(1, notification);
        }
        private global::Android.Net.Uri GetAlarmSound(NotificationOptions options)
        {
            Log.Debug("Alarm", "AlarmNotificationReceiver GetAlarmSound start : " + DateTime.Now.ToString());
            global::Android.Net.Uri alert = null;
            if (options != null && options.EnableSound)
            {
                alert = RingtoneManager.GetDefaultUri(RingtoneType.Alarm);
                if (alert == null)
                {
                    alert = RingtoneManager.GetDefaultUri(RingtoneType.Ringtone);
                }

                Log.Debug("Alarm", "AlarmNotificationReceiver GetAlarmSound alert3 : " + alert?.ToString());
            }

            Log.Debug("Alarm", "AlarmNotificationReceiver GetAlarmSound alert ready: " + alert?.ToString());
            return(alert);
        }
        private void SummaryNotify(Context context)
        {
            var summaryActivityIntent = new Intent(context, typeof(SummaryActivity));
            var pendingIntent         = PendingIntent.GetActivity(context, 0, summaryActivityIntent, 0);
            var builder = new NotificationCompat.Builder(context, AppConstants.ChannelId)
                          .SetContentTitle("Koniec pracy!")
                          .SetStyle(new NotificationCompat.BigTextStyle().BigText(BuildNotificationText()))
                          .SetContentText(BuildNotificationText())
                          .SetSmallIcon(Resource.Drawable.raports)
                          .SetContentIntent(pendingIntent)
                          .SetAutoCancel(true)
                          .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                          .SetDefaults((int)NotificationDefaults.Vibrate)
                          .SetPriority(NotificationCompat.PriorityHigh);
            var notificationManager = NotificationManagerCompat.From(context);

            notificationManager.Notify(AppConstants.NotificationIdAlreadyLeftWork, builder.Build());
        }
Example #7
0
        void createNotification(string title, string desc)
        {
            var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;
            var uiIntent            = new Intent(this, typeof(MainActivity));

            NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

            var notification =
                builder.SetContentIntent(PendingIntent.GetActivity(this, 0, uiIntent, 0))
                .SetSmallIcon(2130837579)
                .SetTicker(title)
                .SetContentTitle(title)
                .SetContentText(desc)
                .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                .SetAutoCancel(true).Build();

            notificationManager.Notify(1, notification);
        }
Example #8
0
        private void CreateNotification(GcmService instance, string subject, string message)
        {
            var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;

            var uiIntent = new Intent(instance, typeof(LoginView));

            NotificationCompat.Builder builder = new NotificationCompat.Builder(instance);
            var notification = builder.SetContentIntent(PendingIntent.GetActivity(instance, 0, uiIntent, PendingIntentFlags.OneShot))
                               .SetSmallIcon(Resource.Drawable.envelope)
                               .SetStyle(new NotificationCompat.BigTextStyle().BigText(message))
                               .SetAutoCancel(true)
                               .SetContentTitle(subject)
                               .SetContentText(message)
                               .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                               .SetAutoCancel(true).Build();

            notificationManager.Notify((int)DateTime.Now.Ticks, notification);
        }
        public override void OnReceive(Context context, Intent intent)
        {
            // Instanciamos
            _medicamento        = new Medicamento();
            _medicamentoService = new MedicamentoService();
            _medicamento        = _medicamentoService.selectMedicamento(); // Selecciona el medicamento

            if (_medicamento != null)
            {
                Intent newIntent = new Intent(context, typeof(MedicamentoAlert));

                // Agrega la siguiente tarea a la pila
                TaskStackBuilder stackBuilder = TaskStackBuilder.Create(context);
                stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MedicamentoAlert)));
                stackBuilder.AddNextIntent(newIntent);

                // Establecer la intencion que se abrira cuando un clic en la notificación
                PendingIntent notificationIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

                // Define bitmap para LargeIcon
                Bitmap bitmap = ((BitmapDrawable)ContextCompat.GetDrawable(context, Resource.Drawable.logo)).Bitmap;

                // Define sound
                Uri soundUri = RingtoneManager.GetDefaultUri(RingtoneType.Alarm);

                // Creamos la Notificacion
                var builder = new NotificationCompat.Builder(context)
                              .SetContentIntent(notificationIntent)
                              .SetSmallIcon(Resource.Drawable.logo)          // Icono pequeño
                              .SetLargeIcon(bitmap)                          // Icono grande
                              .SetContentTitle("Recordar Medicación")        // Titulo
                              .SetContentText("Ver detalles..")              // Contenido
                              .SetSound(soundUri)                            // Sonido
                              .SetVibrate(new long[] { 100, 250, 100, 500 }) // Vibración
                              .SetAutoCancel(true);

                // Mostrar Notificacion
                var manager = (NotificationManager)context.GetSystemService(Context.NotificationService);

                Random random       = new Random(); // id random para notificacion
                int    randomNumber = random.NextInt(9999 - 1000) + 1000;
                manager.Notify(randomNumber, builder.Build());
            }
        }
        public static void NotificationBuildAndShow(Context context, Intent intent)
        {
            var dataBundle = intent.GetBundleExtra("NotificationData");
            var message    = dataBundle.GetString("Message") ?? "My Message";
            var title      = dataBundle.GetString("Title") ?? "My Title";
            var workNo     = dataBundle.GetInt("WORK_NO", 0);
            var logger     = new OurLoggerService();

            logger.LogInformation($"Building and Showing Notification for Work {workNo}");

            var resultIntent = new Intent(context, typeof(MainActivity));

            intent.AddFlags(ActivityFlags.ClearTop);
            var pendingIntent = PendingIntent.GetActivity(context, 0, resultIntent, PendingIntentFlags.UpdateCurrent);

            var importance = NotificationImportance.High;
            NotificationChannel notificationChannel = new NotificationChannel(APP_CHANNEL, "Important", importance);

            notificationChannel.EnableVibration(true);
            notificationChannel.LockscreenVisibility = NotificationVisibility.Public;

            var audioAttributes = new AudioAttributes.Builder()
                                  .SetContentType(AudioContentType.Sonification)
                                  .SetUsage(AudioUsageKind.Alarm)
                                  .Build();

            notificationChannel.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Ringtone), audioAttributes);

            var notificationBuilder = new NotificationCompat.Builder(context, APP_CHANNEL)
                                      .SetSmallIcon(Resource.Mipmap.icon_round)
                                      .SetContentTitle(title)
                                      .SetContentText(message)
                                      .SetContentIntent(pendingIntent)
                                      .SetAutoCancel(false)
                                      .SetChannelId(APP_CHANNEL);

            ;

            NotificationManager notificationManager = (NotificationManager)context.GetSystemService(NotificationService);

            notificationManager.CreateNotificationChannel(notificationChannel);
            notificationManager.Notify(6461, notificationBuilder.Build());
            logger.LogInformation($"Showing Notification for Work {workNo} Complete");
        }
Example #11
0
        /**
         * Creates an inbox style notification summarizing the unread messages
         * in the inbox
         *
         * @param incomingAlert The alert message from an Urban Airship push
         * @return An inbox style notification
         */
        private Android.App.Notification CreateInboxNotification(string incomingAlert)
        {
            Context context = UAirship.Shared().ApplicationContext;

            IList <RichPushMessage> unreadMessages = RichPushInbox.Shared().UnreadMessages;
            int inboxUnreadCount = unreadMessages.Count;

            // The incoming message is not immediately made available to the inbox because it needs
            // to first fetch its contents.
            int totalUnreadCount = inboxUnreadCount + 1;

            Resources res   = UAirship.Shared().ApplicationContext.Resources;
            string    title = res.GetQuantityString(Resource.Plurals.inbox_notification_title, totalUnreadCount, totalUnreadCount);

            Bitmap largeIcon = BitmapFactory.DecodeResource(res, Resource.Drawable.ua_launcher);

            var style = new Notification.InboxStyle(
                new Notification.Builder(context)
                .SetContentTitle(title)
                .SetContentText(incomingAlert)
                .SetLargeIcon(largeIcon)
                .SetSmallIcon(Resource.Drawable.ua_notification_icon)
                .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                .SetNumber(totalUnreadCount));

            // Add the incoming alert as the first line in bold
            style.AddLine(Html.FromHtml("<b>" + incomingAlert + "</b>"));

            // Add any extra messages to the notification style
            int extraMessages = Math.Min(EXTRA_MESSAGES_TO_SHOW, inboxUnreadCount);

            for (int i = 0; i < extraMessages; i++)
            {
                style.AddLine(unreadMessages [i].Title);
            }

            // If we have more messages to show then the EXTRA_MESSAGES_TO_SHOW, add a summary
            if (inboxUnreadCount > EXTRA_MESSAGES_TO_SHOW)
            {
                style.SetSummaryText(context.GetString(Resource.String.inbox_summary, inboxUnreadCount - EXTRA_MESSAGES_TO_SHOW));
            }

            return(style.Build());
        }
        public static void SendSwipeEnabledNotification(Context context)
        {
            var notificationIntent = new Intent(context, typeof(MainActivity));

            notificationIntent.SetFlags(ActivityFlags.SingleTop);

            var pendingIntent = PendingIntent.GetActivity(context, 0, notificationIntent, PendingIntentFlags.UpdateCurrent);

            var notificationBuilder = new NotificationCompat.Builder(context, Constants.NOTIFICTAIONTYPE_CHANNEL_ID)
                                      .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                                      .SetSmallIcon(Resource.Drawable.notify_icon)
                                      .SetContentIntent(pendingIntent)
                                      .SetContentTitle("Dezginspiration")
                                      .SetPriority(NotificationCompat.PriorityDefault)
                                      .SetContentText("Hey, Time to get back to swiping")
                                      .SetAutoCancel(true);

            NotificationManagerCompat.From(Application.Context).Notify(DateTime.Now.Millisecond, notificationBuilder.Build());
        }
Example #13
0
        /// <summary>
        /// Creates a single notification, an instance of <see cref="Android.App.Notification"/> class.
        /// </summary>
        /// <returns>Android notification created from <b>notification</b> parameter.</returns>
        /// <param name="notification"><b>CoreNotification</b></param>
        private Notification GetNotification(CoreNotification notification, DateTime occurrence, Intent notificationIntent)
        {
            var builder = new NotificationCompat.Builder(this.ctx);

            builder.SetContentTitle(notification.Title);
            builder.SetContentText(notification.Message + this.FormatOccurrence(occurrence));
            builder.SetTicker("Ticker");
            builder.SetSmallIcon(Resource.Drawable.Icon);

            builder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Alarm));
            builder.SetPriority((int)NotificationPriority.High);
            builder.SetVisibility((int)NotificationVisibility.Public);  // visible on locked screen

            var action = this.GetAction(builder, notificationIntent, () => { System.Diagnostics.Debug.WriteLine("ACTION!"); });

            builder.AddAction(action);

            return(builder.Build());
        }
        private static void FoundNetworkNotify(Context context, WifiNetwork wifi)
        {
            var startWorkReceiverIntent = new Intent(context, typeof(EnteredWorkReceiver));
            var pendingIntent           = PendingIntent.GetBroadcast(context, 0, startWorkReceiverIntent, PendingIntentFlags.CancelCurrent);
            var builder = new NotificationCompat.Builder(context, AppConstants.ChannelId)
                          .SetContentTitle("Wykryto sieć " + wifi.Ssid)
                          .SetContentText("Kliknij, jeżeli jesteś w pracy.")
                          .SetSmallIcon(Resource.Drawable.raports)
                          .SetContentIntent(pendingIntent)
                          .SetOnlyAlertOnce(true)
                          .SetAutoCancel(true)
                          .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                          .SetDefaults((int)NotificationDefaults.Vibrate)
                          .SetPriority(NotificationCompat.PriorityHigh);

            var notificationManager = NotificationManagerCompat.From(context);

            notificationManager.Notify(AppConstants.NotificationIdStartedWork, builder.Build());
        }
        private static void LostNetworkNotify(Context context)
        {
            var notificationIntent = new Intent(context, typeof(LeftWorkReceiver));
            var pendingIntent      = PendingIntent.GetBroadcast(context, 0, notificationIntent, PendingIntentFlags.CancelCurrent);
            var builder            = new NotificationCompat.Builder(context, AppConstants.ChannelId)
                                     .SetContentTitle("Utracono firmową sieć")
                                     .SetContentText("Kliknij, jeżeli wyszedłeś z pracy.")
                                     .SetSmallIcon(Resource.Drawable.raports)
                                     .SetContentIntent(pendingIntent)
                                     .SetOnlyAlertOnce(true)
                                     .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                                     .SetAutoCancel(true)
                                     .SetDefaults((int)NotificationDefaults.Vibrate)
                                     .SetPriority(NotificationCompat.PriorityHigh);

            var notificationManager = NotificationManagerCompat.From(context);

            notificationManager.Notify(AppConstants.NotificationIdLeftWork, builder.Build());
        }
Example #16
0
        private void SendNotification(string body)
        {
            var intent = new Intent(this, typeof(LogInActivity));

            intent.AddFlags(ActivityFlags.ClearTop);

            var pendingIntent       = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);
            var defaultSoundUri     = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
            var notificationBuilder = new NotificationCompat.Builder(this)
                                      .SetContentTitle("ChatApp")
                                      .SetContentText(body)
                                      .SetAutoCancel(true)
                                      .SetSound(defaultSoundUri)
                                      .SetContentIntent(pendingIntent);

            var notificationManager = NotificationManager.FromContext(this);

            notificationManager.Notify(0, notificationBuilder.Build());
        }
        private void CreateNotification(Context context, string title, string desc, PendingIntent pendingIntent)
        {
            //Create notification
            var notificationManager = context.GetSystemService(Context.NotificationService) as NotificationManager;

            // Get the notificationsound
            var soundUri = RingtoneManager.GetDefaultUri(RingtoneType.Notification);

            //Create the notification
            var notification = new Notification.Builder(Application.Context).SetContentIntent(pendingIntent).SetSmallIcon(Resource.Drawable.Icon).SetContentTitle(desc).SetTicker(title).SetOnlyAlertOnce(true).SetAutoCancel(true).SetSound(soundUri).SetVibrate(new long[] { 1000 }).Build();

            notification.Defaults |= NotificationDefaults.Vibrate;
            notification.Defaults |= NotificationDefaults.Sound;

            //Auto-cancel will remove the notification once the user touches it

            //Show the notification
            notificationManager?.Notify(AndroidPushNotificationService.NotificationId, notification);
        }
Example #18
0
        /// <summary>
        /// 通知を左上に表示する
        /// </summary>
        /// <param name="messageBody">messageBody</param>
        private void SendNotification(string messageBody)
        {
            var intent = new Intent(this, typeof(MainActivity));

            intent.AddFlags(ActivityFlags.ClearTop);
            var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);

            var notificationBuilder = new NotificationCompat.Builder(this, Constant.Android.FireBase.RemoteMessage.Key.ChannelId)
                                      .SetSmallIcon(Resource.Drawable.icon)
                                      .SetContentTitle(Message.PushTitle)
                                      .SetContentText(messageBody)
                                      .SetContentIntent(pendingIntent)
                                      .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                                      .SetAutoCancel(true);

            var notificationManager = NotificationManager.FromContext(this);

            notificationManager.Notify(0, notificationBuilder.Build());
        }
Example #19
0
        public void SendNotification(string messageBody)
        {
            var intent = new Intent(this, typeof(PendingOrdersActivity));

            intent.AddFlags(ActivityFlags.ClearTop);
            var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);

            var notificationBuilder = new NotificationCompat.Builder(this)
                                      .SetContentTitle("BossMandados")
                                      .SetSmallIcon(Resource.Mipmap.Icon)
                                      .SetContentText(messageBody)
                                      .SetAutoCancel(true)
                                      .SetContentIntent(pendingIntent).SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification));


            var notificationManager = NotificationManager.FromContext(this);

            notificationManager.Notify(0, notificationBuilder.Build());
        }
Example #20
0
        void SendNotification(string messageBody)
        {
            var intent = new Intent(this, typeof(MainActivity));

            intent.AddFlags(ActivityFlags.ClearTop);

            var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);

            Bitmap largeIcon = BitmapFactory.DecodeResource(Resources, Resource.Drawable.icon);

            ICharSequence notificationChannelName = new String("ucm");

            NotificationChannel mChannel = Build.VERSION.SdkInt >= BuildVersionCodes.O ? new NotificationChannel("ucm", notificationChannelName, NotificationImportance.High) : null;

            var notificationBuilder = new NotificationCompat.Builder(this)
                                      .SetContentTitle("ucm")
                                      .SetContentText(messageBody)
                                      .SetContentIntent(pendingIntent)
                                      .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                                      .SetStyle(new NotificationCompat.BigTextStyle()
                                                .BigText(messageBody))
                                      .SetLargeIcon(largeIcon)
                                      .SetAutoCancel(true)
                                      .SetVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 })
                                      .SetLights(Color.Yellow, 3000, 3000);

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                notificationBuilder.SetColor(Resource.Color.NotificationsColor);
            }

            notificationBuilder.SetSmallIcon(Resource.Drawable.icon);

            var notificationManager = NotificationManager.FromContext(this);

            if (mChannel != null)
            {
                notificationBuilder.SetChannelId("ucm");
                notificationManager.CreateNotificationChannel(mChannel);
            }

            notificationManager.Notify(0, notificationBuilder.Build());
        }
Example #21
0
        public override void OnReceive(Context context, Intent intent)
        {
            Toast.MakeText(context, "This is my alarm", ToastLength.Short).Show();
            string message = intent.GetStringExtra("message");

            Notification.Builder builder = new Notification.Builder(context).
                                           SetAutoCancel(true).
                                           SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Alarm), Stream.Alarm).
                                           SetContentTitle("Alarm").
                                           SetContentText(message).
                                           SetVibrate(new long[] { 0, 500, 300, 500, 300 }).
                                           SetPriority(4).
                                           SetSmallIcon(Resource.Drawable.ic_notif);

            NotificationManager notificationManager = context.GetSystemService(Context.NotificationService) as NotificationManager;
            Notification        build = builder.Build();

            notificationManager.Notify(0, build);
        }
        void SendNotification(string messageBody)
        {
            var intent = new Intent(this, typeof(MainActivity));

            intent.AddFlags(ActivityFlags.ClearTop);
            var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);

            var notificationBuilder = new NotificationCompat.Builder(this)
                                      .SetSmallIcon(Resource.Drawable.ic_stat_ic_notification)
                                      .SetContentTitle("New Todo Item")
                                      .SetContentText(messageBody)
                                      .SetContentIntent(pendingIntent)
                                      .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                                      .SetAutoCancel(true);

            var notificationManager = NotificationManager.FromContext(this);

            notificationManager.Notify(0, notificationBuilder.Build());
        }
Example #23
0
        private void SendNotification(string body, string title)
        {
            Intent intent = new Intent(this, typeof(MainActivity));

            intent.AddFlags(ActivityFlags.ClearTop);
            PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);

            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                                                             .SetSmallIcon(Resource.Drawable.logo50)
                                                             .SetContentTitle(title)
                                                             .SetContentText(body)
                                                             .SetContentIntent(pendingIntent)
                                                             .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                                                             .SetAutoCancel(true);

            NotificationManager notificationManager = NotificationManager.FromContext(this);

            notificationManager.Notify(0, notificationBuilder.Build());
        }
        private void BtnScreen2_Click(object sender, EventArgs e)
        {
            Intent intent = new Intent(this, typeof(Screen2Activity));
            //StartActivity(intent);
            const int     pendindingIntentId = 0;
            PendingIntent pendingIntent      =
                PendingIntent.GetActivity(this, pendindingIntentId, intent, PendingIntentFlags.OneShot);

            // instantiate builder and set notification elements
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                                                 //Notification.Builder builder = new Notification.Builder(this)
                                                 .SetContentIntent(pendingIntent)
                                                 .SetContentTitle("My 1st Notification")
                                                 .SetContentText("Here is the content from my new notification.")
                                                 .SetSmallIcon(Resource.Drawable.ic_home_black_24dp)
                                                 .SetVisibility(NotificationCompat.VisibilityPublic)
                                                 .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Ringtone)) // ? not obsolete in NotificationCompat !!
                                                 .SetPriority(NotificationCompat.PriorityMax)
            ;
            //// no lockscreen notifications before Android 5.0(API level 21)
            //if ((int)Android.OS.Build.VERSION.SdkInt >= 21)
            //{
            //    builder.SetVisibility(NotificationCompat.VisibilityPublic);
            //}

            //Obsolete code !!!!
            //.SetDefaults(NotificationDefaults.Vibrate)
            //.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Ringtone))


            // build notification
            Notification notification = builder.Build();

            // get the notification manager
            NotificationManager notificationManager =
                GetSystemService(Context.NotificationService) as NotificationManager;

            // publish the notification
            const int notificationId = 0;

            notificationManager.Notify(notificationId, notification);
        }
Example #25
0
        private void _dialogService_NotificateIt(object sender, NotificaiosModel notification)
        {
            // Pass the current button press count value to the next activity:
            Bundle valuesForActivity = new Bundle();


            // When the user clicks the notification, SecondActivity will start up.
            Intent resultIntent = new Intent(this, typeof(MainActivity));

            // Pass some values to SecondActivity:
            resultIntent.PutExtras(valuesForActivity);

            // Construct a back stack for cross-task navigation:
            Android.Support.V4.App.TaskStackBuilder stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(this);
            stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity)));
            stackBuilder.AddNextIntent(resultIntent);

            // Create the PendingIntent with the back stack:
            PendingIntent resultPendingIntent =
                stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

            // Build the notification:
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this)

                                                 .SetAutoCancel(true)                 // Dismiss from the notif. area when clicked
                                                                                      //       .SetContentIntent(resultPendingIntent)  // Start 2nd activity when the intent is clicked.
                                                 .SetContentTitle(notification.title) // Set its title
//                .SetNumber(10)                       // Display the count in the Content Info
                                                 .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                                                 .SetSmallIcon(Resource.Drawable.logo)
                                                 .SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.logo))
                                                 .SetPriority(1)
                                                 .SetVisibility(5)
                                                 .SetVibrate(new long[] { 500, 500 })
                                                 .SetContentText(notification.description); // The message to display.

            // Finally, publish the notification:
            NotificationManager notificationManager =
                (NotificationManager)GetSystemService(Context.NotificationService);

            notificationManager.Notify(++ButtonClickNotificationId, builder.Build());
        }
        private void SendNotification(Bundle extras)
        {
            string msg   = extras.GetString("message");
            string sound = extras.GetString("sound");

            mNotificationManager = (NotificationManager)this.GetSystemService(Context.NotificationService);

            PendingIntent contentIntent = PendingIntent.GetActivity(this, 0, new Intent(this, typeof(SplashScreen)), 0);

            NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
                .SetAutoCancel(true)
                .SetContentTitle(ApplicationInfo.LoadLabel(PackageManager))
                .SetContentIntent(contentIntent)
                .SetStyle(new NotificationCompat.BigTextStyle()
                          .BigText(msg))
                .SetContentText(msg);

            if ((int)Android.OS.Build.VERSION.SdkInt >= 21)
            {
                if (Utility.IsMediabookApp)
                {
                    mBuilder.SetSmallIcon(Resource.Drawable.ic_notification);
                }
                else
                {
                    mBuilder.SetSmallIcon(Resource.Drawable.ic_notification_gen);
                }
            }
            else
            {
                mBuilder.SetSmallIcon(Resource.Drawable.ic_launcher);
            }

            if (sound == "1")
            {
                mBuilder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification));
            }

            mBuilder.SetContentIntent(contentIntent);
            mNotificationManager.Notify(NOTIFICATION_ID, mBuilder.Build());
        }
        private async void ScheduleToast(Context context, MalNotification notification)
        {
            await _toastSemaphore.WaitAsync();

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

            intent.SetAction(DateTime.Now.Ticks.ToString());
            intent.PutExtra("launchArgs", ((notification.Type == MalNotificationsTypes.UserMentions && !notification.IsSupported) ||
                                           notification.Type == MalNotificationsTypes.FriendRequest ||
                                           notification.Type == MalNotificationsTypes.ClubMessages
                                 ? "OpenUrl;"
                                 : "") + notification.LaunchArgs);
            var pendingIntent       = PendingIntent.GetActivity(context, 0, intent, PendingIntentFlags.OneShot);
            var notificationBuilder = new NotificationCompat.Builder(context)
                                      .SetSmallIcon(Resource.Drawable.ic_stat_name)
                                      .SetStyle(new NotificationCompat.BigTextStyle().BigText(notification.Content))
                                      .SetContentTitle(notification.Header)
                                      .SetContentText(notification.Content)
                                      .SetContentInfo(notification.Content)
                                      .SetAutoCancel(true)
                                      .SetGroup(notification.Type.GetDescription())
                                      .SetContentIntent(pendingIntent)
                                      .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification));

            if (notification.Type != MalNotificationsTypes.Messages &&
                notification.Type != MalNotificationsTypes.WatchedTopic)
            {
                var readIntent = new Intent(context, typeof(NotificationClickBroadcastReceiver));
                readIntent.SetAction(DateTime.Now.Ticks.ToString());
                readIntent.PutExtra(NotificationClickBroadcastReceiver.NotificationReadKey, notification.Id);
                var pendingReadIntent = PendingIntent.GetBroadcast(context, 23, readIntent, PendingIntentFlags.OneShot);
                notificationBuilder.AddAction(new NotificationCompat.Action(Resource.Drawable.icon_eye_notification, "Mark as Read",
                                                                            pendingReadIntent));
            }

            var notificationManager = (NotificationManager)context.GetSystemService(Context.NotificationService);

            notificationManager.Notify(notification.Id.GetHashCode(), notificationBuilder.Build());
            await Task.Delay(500);

            _toastSemaphore.Release();
        }
Example #28
0
        private void SendNotification(Intent intent, string messageTitle, string messageBody, long sendTime, RingtoneType ringtoneType = RingtoneType.Alarm)
        {
            intent.AddFlags(ActivityFlags.SingleTop);
            var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);

            var notificationBuilder = new Notification.Builder(this)
                                      .SetSmallIcon(Resource.Drawable.Cook)
                                      .SetContentTitle(messageTitle)
                                      .SetContentText(messageBody)
                                      .SetAutoCancel(true)
                                      .SetContentIntent(pendingIntent)
                                      .SetWhen(sendTime)
                                      .SetVisibility(NotificationVisibility.Public)
                                      .SetDefaults(NotificationDefaults.Sound | NotificationDefaults.Vibrate)
                                      .SetSound(RingtoneManager.GetDefaultUri(ringtoneType));

            var notificationManager = NotificationManager.FromContext(this);

            notificationManager.Notify(0, notificationBuilder.Build());
        }
        /**
         * Create and show a simple notification containing the received FCM message.
         */
        void SendNotification(string messageBody)
        {
            var intent = new Intent(this, typeof(MainActivity));

            intent.AddFlags(ActivityFlags.ClearTop);
            var pendingIntent = PendingIntent.GetActivity(this, 0 /* Request code */, intent, PendingIntentFlags.OneShot);

            var defaultSoundUri     = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
            var notificationBuilder = new NotificationCompat.Builder(this)
                                      .SetSmallIcon(Resource.Drawable.Icon)
                                      .SetContentTitle("Hey ho")
                                      .SetContentText(messageBody)
                                      .SetAutoCancel(true)
                                      .SetSound(defaultSoundUri)
                                      .SetContentIntent(pendingIntent);

            var notificationManager = NotificationManager.FromContext(this);

            notificationManager.Notify(0 /* ID of notification */, notificationBuilder.Build());
        }
Example #30
0
        private void InitAlarm()
        {
            //Init System AlarmManager Class
            _alarmManager = (AlarmManager)context.GetSystemService(Context.AlarmService).JavaCast <AlarmManager>();

            //Create Alarm Pending Intent
            var alarmIntent = new Intent(context, typeof(AlarmReceiver));

            _alarmPendingIntent = PendingIntent.GetBroadcast(context, 1, alarmIntent, PendingIntentFlags.UpdateCurrent);

            //Create ringtone
            var alarmUri = RingtoneManager.GetDefaultUri(RingtoneType.Alarm);

            if (alarmUri == null)
            {
                alarmUri = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
            }

            _ringtone = RingtoneManager.GetRingtone(context, alarmUri);
        }