コード例 #1
0
        private void SendNtfIfRequired(Context context)
        {
            var ntfTextBuilder = new IncompleteTaskNtfTextBuilder(App.Current.TaskManager);
            var strs           = ntfTextBuilder.GetEnumerableStrings();

            if (strs.Count > 0)
            {
                var builder = new NotificationCompat.Builder(context)
                              .SetAutoCancel(true) // Dismiss from the notif. area when clicked
                              .SetContentTitle("TODO")
                              .SetSmallIcon(Resource.Drawable.Icon)
                              .SetContentText("TODO"); // The message to display.

                var inboxStyle = new NotificationCompat.InboxStyle();
                foreach (var str in strs)
                {
                    inboxStyle.AddLine(str);
                }
                builder.SetStyle(inboxStyle);

                // Finally, publish the notification:
                NotificationManager notificationManager =
                    (NotificationManager)context.GetSystemService(Context.NotificationService);
                notificationManager.Notify(_notificationId, builder.Build());
            }
        }
コード例 #2
0
        public void NotifyNewChapters(Context context, List <Chapter> chapters)
        {
            if (chapters.Count < 1)
            {
                return;
            }

            Builder builder = GetBuilder(context, ChannelId.NewChapter);

            builder.SetAutoCancel(true);
            builder.SetNumber(4);
            builder.SetOnlyAlertOnce(true);
            builder.SetContentTitle("1 New Chapter");
            builder.SetContentText(chapters[0].Title);

            Intent intent = new Intent(Intent.ActionView);

            intent.SetData(Uri.Parse(chapters[0].URL));
            intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
            PendingIntent pendingIntent = PendingIntent.GetActivity(context, (int)ChannelId.NewChapter, intent, PendingIntentFlags.OneShot);

            builder.SetContentIntent(pendingIntent);

            if (chapters.Count > 1)
            {
                builder.SetContentTitle($"{chapters.Count} New Chapters");
                builder.SetSubText($"and {chapters.Count - 1} more");

                var inboxStyle = new Notification.InboxStyle(GetBuilder(context, ChannelId.NewChapter));
                inboxStyle.SetBigContentTitle($"{chapters.Count} New Chapters");

                foreach (Chapter chapter in chapters)
                {
                    inboxStyle.AddLine(chapter.Title);
                }

                builder.SetStyle(inboxStyle);
            }
            //Bitmap icon = BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.new_chapter_icon);
            builder.SetSmallIcon(Resource.Drawable.new_chapter_icon);

            NotificationManagerCompat notificationManager = GetManager(context);

            notificationManager.Notify((int)ChannelId.NewChapter, builder.Build());
        }
コード例 #3
0
        //Inbox Style Notification
        void ButtonOnClick4(object sender, EventArgs eventArgs)
        {
            // Pass the current button press count4 value to the next activity:
            var valuesForActivity = new Bundle();

            valuesForActivity.PutInt(COUNT_KEY, count4);

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

            // 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(InboxNotificationActivity)));
            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("Button4 Clicked")    // Set the title
                          .SetSmallIcon(Resource.Drawable.logo)  // This is the icon to display
                          .SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.pic1))
                          .SetPriority(2)
                          .SetContentText($"The button has been clicked {count4} times."); // the message to display.

            // Instantiate the Big Text style:
            //Notification.BigTextStyle textStyle = new Notification.BigTextStyle();

            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
            {
                builder.SetCategory(NotificationCompact.CategoryCall);
            }
            // Convert the image to a bitmap before passing it into the style:
            // Instantiate the Inbox style:
            NotificationCompact.InboxStyle inboxStyle = new NotificationCompact.InboxStyle();

            // Set the title and text of the notification:
            builder.SetContentTitle("5 new messages");
            builder.SetContentText("*****@*****.**");

            // Generate a message summary for the body of the notification:
            inboxStyle.AddLine("Cheeta: Bananas on sale");
            inboxStyle.AddLine("George: Curious about your blog post");
            inboxStyle.AddLine("Nikko: Need a ride to Evolve?");
            inboxStyle.SetSummaryText("+2 more");

            // Plug this style into the builder:
            builder.SetStyle(inboxStyle);
            //builder.SetPriority(NotificationPriority.High);


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

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

            // Increment the button press count4:
            count4++;
        }