//Image Style Notification
        void ButtonOnClick3(object sender, EventArgs eventArgs)
        {
            // Pass the current button press count3 value to the next activity:
            var valuesForActivity = new Bundle();

            valuesForActivity.PutInt(COUNT_KEY, count3);

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

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


            // Construct a back stack for cross-task navigation:
            var stackBuilder = TaskStackBuilder.Create(this);

            stackBuilder.AddParentStack(Class.FromType(typeof(PicNotificationActivity)));
            stackBuilder.AddNextIntent(resultIntent);

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

            // Build the notification:
            var builder = new NotificationCompat.Builder(this, CHANNEL_ID)
                          .SetAutoCancel(true)                                             // Dismiss the notification from the notification area when the user clicks on it
                          .SetContentIntent(resultPendingIntent)                           // Start up this activity when the user clicks the intent.
                          .SetContentTitle("Button3 Clicked")                              // Set the title
                          .SetSmallIcon(Resource.Drawable.logo)                            // This is the icon to display
                          .SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.pic1))
                          .SetContentText($"The button has been clicked {count3} times."); // the message to display.

            // Instantiate the Big Text style:
            //Notification.BigTextStyle textStyle = new Notification.BigTextStyle();
            builder.SetVisibility(NotificationCompact.VisibilitySecret);
            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
            {
                builder.SetCategory(NotificationCompact.CategoryCall);
            }
            // Instantiate the Image (Big Picture) style:
            NotificationCompact.BigPictureStyle picStyle = new NotificationCompact.BigPictureStyle();

            // Convert the image to a bitmap before passing it into the style:
            picStyle.BigPicture(BitmapFactory.DecodeResource(Resources, Resource.Drawable.pic1));

            // Set the summary text that will appear with the image:
            picStyle.SetSummaryText("The summary text goes here.");

            // Plug this style into the builder:
            builder.SetStyle(picStyle);


            // Finally, publish the notification:
            var notificationManager = NotificationManagerCompat.From(this);

            notificationManager.Notify(NOTIFICATION_ID3, builder.Build());

            // Increment the button press count3:
            count3++;
        }
Example #2
0
        private void ShowWalkNotification()
        {
            // When the user clicks the notification, SecondActivity will start up.
            Intent resultIntent = new Intent(this, typeof(WalkActivity));

            // Construct a back stack for cross-task navigation:
            TaskStackBuilder stackBuilder = TaskStackBuilder.Create(this);

            stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(WalkActivity)));
            stackBuilder.AddNextIntent(resultIntent);

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

            //create notification for walk-screen
            NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(this)
                                                  .SetSmallIcon(Resource.Drawable.Icon)
                                                  .SetContentTitle("Are you stressed?")
                                                  .SetContentIntent(resultPendingIntent)
                                                  .SetContentText("Maybe a short walk would do good?")
                                                  .SetPriority((int)NotificationPriority.High)//priority is high because user can be in danger!
                                                  .SetAutoCancel(true);

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

            notificationManager.Notify(10001, nBuilder.Build());
        }
Example #3
0
        void ButtonOnClick()
        {
            // Pass the current button press count value to the next activity:
            var valuesForActivity = new Bundle();

            valuesForActivity.PutInt(COUNT_KEY, 2);

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

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

            // Construct a back stack for cross-task navigation:
            var stackBuilder = TaskStackBuilder.Create(this);

            stackBuilder.AddParentStack(Class.FromType(typeof(SecondActivity)));
            stackBuilder.AddNextIntent(resultIntent);

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

            // Build the notification:
            var builder = new NotificationCompat.Builder(this, CHANNEL_ID)
                          .SetAutoCancel(true)                      // Dismiss the notification from the notification area when the user clicks on it
                          .SetContentIntent(resultPendingIntent)    // Start up this activity when the user clicks the intent.
                          .SetContentTitle("Notification")          // Set the title
                          .SetSmallIcon(Resource.Drawable.logo)     // This is the icon to display
                          .SetContentText($"Notification Sample."); // the message to display.

            // Finally, publish the notification:
            var notificationManager = NotificationManagerCompat.From(this);

            notificationManager.Notify(NOTIFICATION_ID, builder.Build());
        }
        private void HandleMessage(Context context, Intent intent)
        {
            Intent           resultIntent = new Intent(this, typeof(MainActivity));
            TaskStackBuilder stackBuilder = TaskStackBuilder.Create(this);
            var c = Class.FromType(typeof(MainActivity));

            stackBuilder.AddParentStack(c);
            stackBuilder.AddNextIntent(resultIntent);
            string        alert               = intent.GetStringExtra("Alert");
            int           number              = intent.GetIntExtra("Badge", 0);
            var           imageUrl            = intent.GetStringExtra("ImageUrl");
            var           title               = intent.GetStringExtra("Title");
            Bitmap        bitmap              = GetBitmap(imageUrl);
            PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                                                 .SetAutoCancel(true)                   // dismiss the notification from the notification area when the user clicks on it
                                                 .SetContentIntent(resultPendingIntent) // start up this activity when the user clicks the intent.
                                                 .SetContentTitle(title)                // Set the title
                                                 .SetNumber(number)                     // Display the count in the Content Info
                                                 .SetSmallIcon(Resource.Drawable.Icon)  // This is the icon to display
                                                 .SetLargeIcon(bitmap)
                                                 .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                                                 .SetContentText(alert); // the message to display.
            // Build the 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 #5
0
        private PendingIntent InitResultIntentBasingOnViewModel(NotificationViewModel notificationViewModel)
        {
            // When the user clicks the notification, SecondActivity will start up.
            Intent resultIntent;

            // Construct a back stack for cross-task navigation:
            TaskStackBuilder stackBuilder = TaskStackBuilder.Create(NotificationContext);

            if (OnboardingStatusHelper.Status == OnboardingStatus.CountriesOnboardingCompleted &&
                notificationViewModel.Type == NotificationsEnum.NewMessageReceived.Data().Type)
            {
                resultIntent = new Intent(NotificationContext, typeof(MessagesActivity));
                stackBuilder.AddParentStack(Class.FromType(typeof(MessagesActivity)));
            }
            else
            {
                resultIntent = new Intent(NotificationContext, typeof(InitializerActivity));
                stackBuilder.AddParentStack(Class.FromType(typeof(InitializerActivity)));
            }

            stackBuilder.AddNextIntent(resultIntent);

            // Create the PendingIntent with the back stack:
            return(stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent));
        }
        void HandleTimerCallback(object state)
        {
            var preferences     = PreferenceManager.GetDefaultSharedPreferences(this);
            var streamerNames   = preferences.GetString("streamer_names", "").Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            var streamersOnline = Twitch.StreamersOnline(streamerNames, configuration);

            foreach (var entry in streamersOnline)
            {
                if (!entry.Value)
                {
                    continue;
                }

                Bundle valuesForActivity = new Bundle();
                Intent resultIntent      = new Intent(this, typeof(MainActivity));
                resultIntent.PutExtras(valuesForActivity);

                TaskStackBuilder stackBuilder = TaskStackBuilder.Create(this);
                stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity)));
                stackBuilder.AddNextIntent(resultIntent);

                PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

                NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                                                     .SetAutoCancel(true)
                                                     .SetContentIntent(resultPendingIntent)
                                                     .SetContentTitle("Streamer online")
                                                     .SetSmallIcon(Resource.Drawable.Icon)
                                                     .SetContentText(entry.Key + " is streaming now");

                NotificationManager notificationManager = (NotificationManager)GetSystemService(NotificationService);
                notificationManager.Notify(ButtonClickNotificationId, builder.Build());
            }
        }
Example #7
0
        public void Notify(string title, string body, int id = 0)
        {
            if (!_channelInitialized)
            {
                Initialize();
            }

            Intent resultIntent = GetLauncherActivity();

            resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
            TaskStackBuilder stackBuilder = TaskStackBuilder.Create(AndroidApp.Context);

            stackBuilder.AddNextIntent(resultIntent);
            PendingIntent resultPendingIntent =
                stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(AndroidApp.Context, _channelId)
                                                 .SetContentIntent(resultPendingIntent)
                                                 .SetContentTitle(title)
                                                 .SetContentText(body)
                                                 .SetLargeIcon(BitmapFactory.DecodeResource(AndroidApp.Context.Resources,
                                                                                            Resource.Drawable.notification_icon))
                                                 .SetSmallIcon(Resource.Drawable.notification_icon)
                                                 .SetDefaults((int)NotificationDefaults.All);

            Notification notification = builder.Build();

            NotificationManager.Notify(id, notification);
        }
        public override void OnReceive(Context context, Intent intent)
        {
            reminder = ReminderHelper.SelectReminder(context);
            if (reminder != null)
            {
                Intent newIntent = new Intent(context, typeof(ReminderContent));
                newIntent.PutExtra("reminder", JsonConvert.SerializeObject(reminder));

                //Add the next task to the stack
                Android.Support.V4.App.TaskStackBuilder stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(context);
                stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(ReminderContent)));
                stackBuilder.AddNextIntent(newIntent);

                // set the intent which will open when one click on notification
                PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

                NotificationCompat.Builder builder = new NotificationCompat.Builder(context).SetAutoCancel(true)
                                                     .SetDefaults((int)NotificationDefaults.All)
                                                     .SetContentIntent(resultPendingIntent).SetContentTitle("Reminder!!")
                                                     .SetSmallIcon(Resource.Drawable.notify_panel_notification_icon_bg).SetContentText("Click for details..")
                                                     .SetContentInfo("Start");
                NotificationManager notificationManager = (NotificationManager)context.GetSystemService(Context.NotificationService);
                notificationManager.Notify(2, builder.Build());
            }
        }
        private void ButtonOnCLick(object sender, EventArgs eventArgs)
        {
            var valuesForActivity = new Bundle();

            valuesForActivity.PutInt(CountKey, Count);

            var intent = new Intent(this, typeof(SecondActivity));

            intent.PutExtras(valuesForActivity);

            var stackBuilder = TaskStackBuilder.Create(this);

            stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(SecondActivity)));
            stackBuilder.AddNextIntent(intent);

            var pendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

            var builder = new NotificationCompat.Builder(this, ChannelId)
                          .SetAutoCancel(true)
                          .SetContentIntent(pendingIntent)
                          .SetContentTitle("Button clicked")
                          .SetNumber(Count)
                          .SetSmallIcon(Resource.Drawable.ic_stat_button_click)
                          .SetContentText($"The button has been clicked {Count} times.");

            var notificationManager = NotificationManagerCompat.From(this);

            notificationManager.Notify(NotificationId, builder.Build());

            Count++;
        }
        public override void OnReceive(Context context, Intent intent)
        {
            PendingIntent pi      = PendingIntent.GetActivity(context, 0, intent, 0);
            AlarmManager  manager = (AlarmManager)context.GetSystemService(Android.Content.Context.AlarmService);

            manager.Cancel(pi);

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

            // Construct a back stack for cross-task navigation:
            TaskStackBuilder stackBuilder = TaskStackBuilder.Create(context);

            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 Notification
            NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                                                 .SetAutoCancel(true)
                                                 .SetDefaults((int)NotificationDefaults.Sound)
                                                 .SetContentIntent(resultPendingIntent)
                                                 .SetContentTitle("Notification ALARM!!!")
                                                 .SetSmallIcon(Resource.Drawable.ic_stat_button_click)
                                                 .SetContentText(string.Format("You are OUT!!."));

            //Send Notification
            NotificationManager nf = (NotificationManager)context.GetSystemService(Context.NotificationService);

            nf.Notify(1000, builder.Build());

            MainActivity.CloseThis();
        }
Example #11
0
        private void CreateNotification(SongBundle song)
        {
            Log(Type.Info, "Creating notification");

            Intent info = new Intent(Application.Context, typeof(MainActivity));

            info.PutExtra("NotificationSong", JsonConvert.SerializeObject(song));

            TaskStackBuilder stackBuilder = TaskStackBuilder.Create(Application.Context);

            stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity)));
            stackBuilder.AddNextIntent(info);

            PendingIntent resultIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(this, ChannelId)
                                                 .SetAutoCancel(true)
                                                 .SetContentTitle(Resources?.GetString(Resource.String.app_name))
                                                 .SetContentText(song.Normal.Artist + " - " + song.Normal.Title)
                                                 .SetSmallIcon(Resource.Drawable.ic_stat_name)
                                                 .SetContentIntent(resultIntent)
                                                 .SetPriority(-1);

            ntfManager = NotificationManagerCompat.From(Application.Context);
            ntfManager.Notify(NotificationId, builder.Build());
            Log(Type.Event, "Notification made!");
        }
        public static void NavigateUp(Activity activity, Bundle extras = null)
        {
            Intent upIntent = NavUtils.GetParentActivityIntent(activity);

            if (upIntent != null)
            {
                if (extras != null)
                {
                    upIntent.PutExtras(extras);
                }

                if (NavUtils.ShouldUpRecreateTask(activity, upIntent))
                {
                    TaskStackBuilder.Create(activity)
                    .AddNextIntentWithParentStack(upIntent)
                    .StartActivities();
                }
                else
                {
                    upIntent.AddFlags(ActivityFlags.ClearTop);
                    activity.StartActivity(upIntent);
                }
            }
            activity.Finish();
        }
Example #13
0
        public void PushNotif()
        {
            var valuesForActivity = new Bundle();

            count = minDateTime.ToString("yyyy-MM-dd HH:mm:ss");
            valuesForActivity.PutString(COUNT_KEY, count);

            var resultIntent = new Intent(this, typeof(SecondActivity));

            resultIntent.PutExtras(valuesForActivity);

            var stackBuilder = TaskStackBuilder.Create(this);

            stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(SecondActivity)));
            stackBuilder.AddNextIntent(resultIntent);

            var resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

            var builder = new NotificationCompat.Builder(this, CHANNEL_ID)
                          .SetAutoCancel(true)
                          .SetContentIntent(resultPendingIntent)
                          .SetContentTitle("Button Clicked")
                          .SetSmallIcon(Resource.Mipmap.notification)
                          .SetContentText($" {count} ");

            var notificationManager = NotificationManagerCompat.From(this);

            notificationManager.Notify(NOTIFICATION_ID, builder.Build());
        }
        private void SendMyNotification(string title, string description, string channelID, string channelName, string channelDescription, bool serviceNotification)
        {
            // When the user clicks the notification, SecondActivity will start up.
            Intent        resultIntent = new Intent(this, typeof(MainActivity));
            PendingIntent resultPendingIntent;

            if (serviceNotification)
            {
                resultPendingIntent = null;
            }
            else
            {
                resultIntent.SetAction("Main_Activity");
                resultIntent.SetFlags(ActivityFlags.SingleTop | ActivityFlags.ClearTask);

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

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

            //Build Notification
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelID)
                                                 .SetAutoCancel(true)
                                                 .SetContentIntent(resultPendingIntent)
                                                 .SetContentTitle(title)
                                                 .SetSmallIcon(Resource.Drawable.notification_icon_background)
                                                 .SetOngoing(true)
                                                 .SetContentText(string.Format(description));

            NotificationManager nf = (NotificationManager)GetSystemService(NotificationService);

            //Creating a Channel
            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.
                NotificationChannel nc = new NotificationChannel(channelID, channelName, NotificationImportance.Default)
                {
                    Description = channelDescription
                };

                nf.CreateNotificationChannel(nc);
            }

            //Send Notification
            if (serviceNotification)
            {
                StartForeground(10000, builder.Build());
            }
            else
            {
                nmc = NotificationManagerCompat.From(this);
                nmc.Notify(1000, builder.Build());
            }
        }
Example #15
0
        /*
         * void createNotification(string title, string desc)
         * {
         *      //Create notification
         *      var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;
         *
         *      //Create an intent to show ui
         *      var uiIntent = new Intent(this, typeof(MainActivity));
         *
         *      //Create the notification
         *      var notification = new Notification(Android.Resource.Drawable.SymActionEmail, title);
         *
         *      //Auto cancel will remove the notification once the user touches it
         *      notification.Flags = NotificationFlags.AutoCancel;
         *
         *      //Set the notification info
         *      //we use the pending intent, passing our ui intent over which will get called
         *      //when the notification is tapped.
         *      notification.SetLatestEventInfo(this, title, desc, PendingIntent.GetActivity(this, 0, uiIntent, 0));
         *
         *      //Show the notification
         *      notificationManager.Notify(1, notification);
         * }
         */

        private void updateNotification(int num, string msg, int notificationID, string url)
        {
            // These are the values that we want to pass to the next activity
            Bundle valuesForActivity = new Bundle();

            valuesForActivity.PutInt(GF.CALL_FROM_NOTI_TYPE, notificationID);
            valuesForActivity.PutString(GF.URL_FROM_NOTI, url);

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

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

            Android.Support.V4.App.TaskStackBuilder stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(this);
            stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity)));
            stackBuilder.AddNextIntent(resultIntent);

            PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

            //Android.Net.Uri alarmSound = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
            Android.Net.Uri alarmSound;             //= Android.Net.Uri.Parse ("android.resource://" + PackageName + "/" + Resource.Raw.noti_sound_coin);
            string          msgText;

            if (Ini.checkNotiId(notificationID))
            {
                alarmSound = Ini.DefaultNotiAudio;                //Ini.NotiAudioList [notificationID];
                msgText    = Ini.NotiTitleList [notificationID];
            }
            else
            {
                alarmSound = Ini.DefaultNotiAudio;
                msgText    = Ini.DefaultNotiTitle;
            }

            GF.devLog("[GcmService] notificationID: " + notificationID + "  msgText: " + msgText);

            // Build the notification
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                                                 .SetAutoCancel(true)                        // dismiss the notification from the notification area when the user clicks on it
                                                 .SetContentIntent(resultPendingIntent)      // start up this activity when the user clicks the intent.
                                                 .SetContentTitle(num.ToString() + msgText)  // Set the title
                                                 .SetSmallIcon(Resource.Drawable.Icon)       // This is the icon to display
                                                 .SetSound(alarmSound, 5)
                                                 .SetContentText(msg.Replace("</br>", " ")); // the message to display.
            //.SetContentInfo ("info")
            //.SetNumber (num); // Display the count in the Content Info

            // Finally publish the notification
            NotificationManager notificationManager = (NotificationManager)GetSystemService(NotificationService);

            notificationManager.Notify(notificationID, builder.Build());
        }
        void createNotification(string title, string desc, int id = 0)
        {
            // Pass the current button press count value to the next activity:
            Bundle valuesForActivity = new Bundle();

            valuesForActivity.PutInt("feedId", id);

            // 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:
            TaskStackBuilder stackBuilder = 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);

            // vibration Pattern
            long[] pattern = { 500, 500, 500, 800, 500 };


            // 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(title)
                                                                                        //.SetNumber(777)                       // Display the count in the Content Info
                                                                                        //.SetLights( Color.BLUE, 500, 500)
                                                 .SetLights(global::Android.Graphics.Color.Blue, 300, 1000)

                                                 .SetVibrate(pattern)
                                                 .SetSmallIcon(Resource.Drawable.ic_launcher) // Display this icon
                                                 .SetTicker(desc)
                                                 .SetSound(GetNotificationSound(0))
                                                 .SetStyle(new NotificationCompat.BigTextStyle().BigText(desc))
                                                 .SetContentText(desc); // The message to display.


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

            notificationManager.Notify(id, builder.Build());

            // Increment the button press count:
        }
Example #17
0
        private PendingIntent GetIntentToMainActivity(int notificationId)
        {
            //we use the main because we dont want to show the splash again..
            var resultIntent = new Intent(Application.Context, typeof(MainActivity));
            var bundle       = new Bundle();

            bundle.PutString(nameof(NotificationService), $"{notificationId}");
            var pendingIntent = TaskStackBuilder.Create(Application.Context)
                                .AddNextIntent(resultIntent)
                                .GetPendingIntent(1, (int)PendingIntentFlags.UpdateCurrent, bundle);

            return(pendingIntent);
        }
        public void Notify(Intent intent)
        {
            var    rand              = new Random();
            var    randomNum         = rand.Next();
            Bundle valuesForActivity = new Bundle();

            valuesForActivity.PutInt("topicId", randomNum);

            Global.SetNotifTopic(intent.Extras.GetString("push_type"));
            Global.SetListTopic(randomNum, intent.Extras.GetString("push_type"));


            Intent resultIntent = new Intent(this, typeof(MainActivity));

            resultIntent.PutExtras(valuesForActivity);

            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);

            var fullmessage = intent.Extras.GetString("message") + "\n" + intent.Extras.GetString("article_data");
            var imageBitmap = GetImageBitmapFromUrl(intent.Extras.GetString("image_url"));

            NotificationCompat.BigPictureStyle picstyle = new NotificationCompat.BigPictureStyle();
            picstyle.BigPicture(imageBitmap);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                                                 .SetAutoCancel(true)
                                                 .SetContentIntent(resultPendingIntent)
                                                 .SetContentTitle(intent.Extras.GetString("title"))
                                                 .SetNumber(Global.GetNotifCount())
                                                 .SetStyle(picstyle)
                                                 .SetSmallIcon(Resource.Drawable.UmbrellaArmyFavicon)
                                                 .SetContentText(String.Format(fullmessage));

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

            notificationManager.Notify(ButtonClickNotificationId, builder.Build());

            if (Global.GetNotifTopic() != "general" || Global.GetNotifTopic() != "general_android")
            {
                var message = new StartLongRunningTaskMessage();
                MessagingCenter.Send(message, "StartLongRunningTaskMessage");
            }
        }
Example #19
0
        public void ShowTaskReminderNotification(TaskReminderNotification notification)
        {
            //we create the pending intent when the user clicks the notification...
            var action = new NotificationAction
            {
                Action     = NotificationActionType.OPEN_TASK,
                TaskId     = notification.TaskId,
                TaskListId = notification.TaskListId
            };
            var clickIntent = MainActivity.CreateIntent(
                notification.Id,
                MainActivity.InitParamsKey,
                JsonConvert.SerializeObject(action));

            var pendingIntent = TaskStackBuilder.Create(Application.Context)
                                .AddNextIntent(clickIntent)
                                .GetPendingIntent(1, (int)PendingIntentFlags.UpdateCurrent);

            var localNotification = new TaskNotification
            {
                LargeContent =
                    $"{notification.TaskTitle}{System.Environment.NewLine}" +
                    $"{notification.TaskBody}",
                Title = notification.TaskListTitle,
                Id    = notification.Id
            };
            var builder = BuildSimpleNotification(localNotification);

            builder.SetContentIntent(pendingIntent);

            //we create the pending intent when the user clicks the mark as completed button...
            var mcIntent = MarkTaskAsCompletedReceiver.CreateIntent(
                notification.Id,
                MarkTaskAsCompletedReceiver.MarkTaskAsCompletedKey,
                JsonConvert.SerializeObject(notification));

            var mcPendingIntent = PendingIntent.GetBroadcast(
                Application.Context,
                0,
                mcIntent,
                0);

            string title = _textProvider.Get("MarkTaskAs", _textProvider.Get("Completed"));

            builder.AddAction(Resource.Drawable.ic_check_white_48dp, title, mcPendingIntent);

            var notif = builder.Build();

            NotifManager.Notify(notification.Id, notif);
        }
Example #20
0
 public void ShowPresetNotification(Notification.Builder builder)
 {
     using (Intent resultIntent = new Intent(AppContext, typeof(Activity)))
     {
         PendingIntent resultPendingIntent;
         var           notificationManager = GetNotificationManager();
         resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
         using (TaskStackBuilder stackBuilder = TaskStackBuilder.Create(AppContext))
         {
             stackBuilder.AddNextIntent(resultIntent);
             resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);
         }
         builder.SetContentIntent(resultPendingIntent);
         notificationManager.Notify(1000, builder.Build());
     }
 }
Example #21
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.LocalNotificationView);

            var txtMessage = FindViewById <EditText> (Resource.Id.txtMessage);
            var btnSend    = FindViewById <Button> (Resource.Id.btnSend);

            btnSend.Click += (object sender, EventArgs e) => {
                //
                Bundle valuesForActivity = new Bundle();
                valuesForActivity.PutString("message", txtMessage.Text);

                Intent resultIntent = new Intent(this, typeof(NotificationProcessingActivity));
                resultIntent.PutExtras(valuesForActivity);

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

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


                //

                NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                                                     .SetAutoCancel(true)                                  //
                                                     .SetContentIntent(resultPendingIntent)                // 使用者按下通知後,負責處理的 Activity
                                                     .SetContentTitle("Android Tips")                      // Title
                                                     .SetNumber(1)                                         // Display the count in the Content Info
                                                     .SetSmallIcon(Resource.Drawable.ic_stat_button_click) // Icon,必備
                                                     .SetContentText(txtMessage.Text);                     // 要顯示的訊息

                // 註冊系統服務
                NotificationManager notificationManager =
                    (NotificationManager)GetSystemService(Context.NotificationService);

                notificationManager.Notify(ButtonClickNotificationId, builder.Build());
            };
        }
        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());
            }
        }
Example #23
0
        /// <summary>
        /// Method to create a notification, requires activity components to build
        /// </summary>
        /// <param name="title"></param>
        /// <param name="text"></param>
        public void CreateNotification(string title, string text)
        {
            // Return if the app is running in the foreground as we do not want to create a notification
            if (!App.Minimised)
            {
                return;
            }

            PowerManager pm = (PowerManager)GetSystemService(Context.PowerService);

            PowerManager.WakeLock wakeLock = pm.NewWakeLock(WakeLockFlags.Partial, "BackgroundReceiver");
            wakeLock.Acquire();

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


            // Construct a back stack for cross-task navigation:
            TaskStackBuilder stackBuilder = 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(title)                        // Set its title
                                                 .SetSmallIcon(Resource.Drawable.shopping_list) // Display this icon
                                                 .SetContentText(text);                         // The message to display.

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

            notificationManager.Notify(1000, builder.Build());

            wakeLock.Release();
        }
Example #24
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());
        }
Example #25
0
        private void ButtonOnClick(object sender, EventArgs eventArgs)
        {
            // Pass the current button press count value to the next activity:
            Bundle valuesForActivity = new Bundle();

            valuesForActivity.PutInt("count", count);

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

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

            // Construct a back stack for cross-task navigation:
            TaskStackBuilder stackBuilder = TaskStackBuilder.Create(this);

            stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(SecondActivity)));
            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("Button Clicked")                                     // Set its title
                                                 .SetNumber(count)                                                      // Display the count in the Content Info
                                                 .SetSmallIcon(Resource.Drawable.ic_stat_button_click)                  // Display this icon
                                                 .SetContentText(String.Format(
                                                                     "The button has been clicked {0} times.", count)); // The message to display.

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

            notificationManager.Notify(ButtonClickNotificationId, builder.Build());

            // Increment the button press count:
            count++;
        }
Example #26
0
        public override void OnReceive(Context context, Intent intent)
        {
            var extra = intent.GetStringExtra(AlarmNotificationKey);
            LocalNotification notification = DeserializeNotification(extra);
            var builder = notification.GenerateNotification();

            using (Intent resultIntent = new Intent(AppContext, typeof(Activity)))
            {
                PendingIntent resultPendingIntent;
                var           notificationManager = GetNotificationManager();
                resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
                using (TaskStackBuilder stackBuilder = TaskStackBuilder.Create(AppContext))
                {
                    stackBuilder.AddNextIntent(resultIntent);
                    resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);
                }
                builder.SetContentIntent(resultPendingIntent);
                notificationManager.Notify(1000, builder.Build());
            }
        }
Example #27
0
        private static void NotifyHeartRate(Context context, user_page userPage, int HR, HRStatus status)
        {
            // When the user clicks the notification, SecondActivity will start up.
            Intent resultIntent = new Intent(userPage, typeof(NotificationActivity));

            // Passing HR and HRStatus to notification activity
            Bundle valuesForActivity = new Bundle();

            valuesForActivity.PutInt("status", (int)status);
            valuesForActivity.PutInt("HR", HR);
            resultIntent.PutExtras(valuesForActivity);

            // Construct a back stack for cross-task navigation:
            TaskStackBuilder stackBuilder = TaskStackBuilder.Create(context);

            stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(NotificationActivity)));
            stackBuilder.AddNextIntent(resultIntent);

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

            // Build the notification:
            NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                                                 .SetAutoCancel(true)                              // Dismiss from the notif. area when clicked
                                                 .SetContentIntent(resultPendingIntent)            // Start 2nd activity when the intent is clicked.
                                                 .SetContentTitle("Is everything OK?")             // Set its title
                                                 .SetNumber(HR)                                    // Display the HR in the Content Info
                                                 .SetSmallIcon(Resource.Drawable.emptyheart_white) // Display this icon
                                                 .SetContentText(string.Format(
                                                                     "Your heart beat {0} to {1} bpm.",
                                                                     status == HRStatus.Hypo ? "decreased dramaticaly" :
                                                                     status == HRStatus.Hyper ? "increased dramaticaly" :
                                                                     "is not stable and changed dramatically", HR)); // The message to display.

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

            notificationManager.Notify(ButtonClickNotificationId, builder.Build());
        }
Example #28
0
        private Notification CreateNotification(string contentText)
        {
            var intent = new Intent(this, typeof(MainActivity));

            intent.SetFlags(ActivityFlags.ClearTop);

            var stackBuilder = TaskStackBuilder.Create(this)
                               .AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity)))
                               .AddNextIntent(intent);

            var pendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

            return(new NotificationCompat.Builder(this, ServiceNotificationChannelId)
                   .SetAutoCancel(true)
                   .SetContentIntent(pendingIntent)
                   .SetContentTitle(GetString(Resource.String.channel_description))
                   .SetSmallIcon(Android.Resource.Drawable.StatSysDataBluetooth)
                   .SetContentText(contentText)
                   .SetVisibility((int)NotificationVisibility.Public)
                   .Build());
        }
        private void ButtonOnClick(object sender, System.EventArgs e)
        {
            // Pass the current button press count value to the next activity:
            var valuesForActivity = new Bundle();

            valuesForActivity.PutInt(COUNT_KEY, count);

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

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

            // Construct a back stack for cross-task navigation:
            //var stackBuilder = TaskStackBuilder.Create(this);
            var stackBuilder = TaskScheduler.Create(this);

            stackBuilder.AddParentStack(Class.FromType(typeof(SecondActivity)));
            stackBuilder.AddNextIntent(resultIntent);

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

            // Build the notification:
            var builder = new NotificationCompat.Builder(this, CHANNEL_ID)
                          .SetAutoCancel(true)                                            // Dismiss the notification from the notification area when the user clicks on it
                          .SetContentIntent(resultPendingIntent)                          // Start up this activity when the user clicks the intent.
                          .SetContentTitle("Button Clicked")                              // Set the title
                          .SetNumber(count)                                               // Display the count in the Content Info
                          .SetSmallIcon(Resource.Drawable.ic_stat_button_click)           // This is the icon to display
                          .SetContentText($"The button has been clicked {count} times."); // the message to display.

            // Finally, publish the notification:
            var notificationManager = NotificationManagerCompat.From(this);

            notificationManager.Notify(NOTIFICATION_ID, builder.Build());

            // Increment the button press count:
            count++;
        }
Example #30
0
        public override void OnReceive(Context context, Intent intent)
        {
            var message = intent.GetStringExtra("message");
            var title   = intent.GetStringExtra("title");

            // Pass the current button press count value to the next activity:
            var valuesForActivity = new Bundle();

            valuesForActivity.PutInt(MainActivity.COUNT_KEY, MainActivity.count);

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

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

            // Construct a back stack for cross-task navigation:
            //var stackBuilder = TaskStackBuilder.Create(this);
            var stackBuilder = TaskScheduler.Create(context);

            stackBuilder.AddParentStack(Class.FromType(typeof(SecondActivity)));
            stackBuilder.AddNextIntent(resultIntent);

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

            // Build the notification:
            var notificationBuilder = new NotificationCompat.Builder(context, MainActivity.CHANNEL_ID)
                                      .SetAutoCancel(true)                                  // Dismiss the notification from the notification area when the user clicks on it
                                      .SetContentIntent(resultPendingIntent)                // Start up this activity when the user clicks the intent.
                                      .SetContentTitle(title)                               // Set the title
                                      .SetNumber(MainActivity.count)                        // Display the count in the Content Info
                                      .SetSmallIcon(Resource.Drawable.ic_stat_button_click) // This is the icon to display
                                      .SetContentText(message);                             // the message to display.

            // Finally, publish the notification:
            var notificationManager = NotificationManagerCompat.From(context);

            notificationManager.Notify(MainActivity.NOTIFICATION_ID, notificationBuilder.Build());
        }