question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Guide set but notification not work

See original GitHub issue

Hi there,

We have tried to add https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/send-local-toast.

Our Notification.cs :

using Windows.UI.Notifications;
using Microsoft.Toolkit.Uwp.Notifications; // Notifications library
using Microsoft.QueryStringDotNET; // QueryString.NET

namespace LaraveX
{
    // https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/send-local-toast
    class Notification
    {
        static ToastVisual visual { get; set; }
        static ToastActionsCustom actions { get; set; }
        static ToastContent toastContent { get; set; }

        static int conversationId { get; set; }
        static string image { get; set; }
        static string logo { get; set; }

        public static void send(string title, string content, string icon = null)
        {
            LoadVisual(title, content, icon); LoadActions(); LoadContent();

            // And create the toast notification
            var toast = new ToastNotification(toastContent.GetXml());

            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }

        static void LoadVisual(string title, string content, string icon = null)
        {
            // In a real app, these would be initialized with actual data
            image = "http://www.laravex.com/assets/images/72ppi/logo.png";
            logo = Sys.DIR + @"/logo.png";

            // Construct the visuals of the toast
            visual = new ToastVisual()
            {
                BindingGeneric = new ToastBindingGeneric()
                {
                    Children =
                    {
                        new AdaptiveText()
                        {
                            Text = title
                        },

                        new AdaptiveText()
                        {
                            Text = content
                        },

                        new AdaptiveImage()
                        {
                            Source = image
                        }
                    },

                    AppLogoOverride = new ToastGenericAppLogo()
                    {
                        Source = logo,
                        HintCrop = ToastGenericAppLogoCrop.Circle
                    }
                }
            };

        }

        static void LoadActions()
        {
            // In a real app, these would be initialized with actual data
            conversationId = 384928;

            // Construct the actions for the toast (inputs and buttons)
            ToastActionsCustom actions = new ToastActionsCustom()
            {
                Inputs =
                    {
                        new ToastTextBox("tbReply")
                        {
                            PlaceholderContent = "Type a response"
                        }
                    },

                Buttons =
                    {
                        new ToastButton("Reply", new QueryString()
                        {
                            { "action", "reply" },
                            { "conversationId", conversationId.ToString() }

                        }.ToString())
                        {
                            ActivationType = ToastActivationType.Background,
                            ImageUri = Sys.DIR + @"/logo.png",
 
                            // Reference the text box's ID in order to
                            // place this button next to the text box
                            TextBoxId = "tbReply"
                        },

                        new ToastButton("Like", new QueryString()
                        {
                            { "action", "like" },
                            { "conversationId", conversationId.ToString() }

                        }.ToString())
                        {
                            ActivationType = ToastActivationType.Background
                        },

                        new ToastButton("View", new QueryString()
                        {
                            { "action", "viewImage" },
                            { "imageUrl", image }

                        }.ToString())
                    }
            };
        }

        static void LoadContent()
        {
            // Now we can construct the final toast content
            ToastContent toastContent = new ToastContent()
            {
                Visual = visual,
                Actions = actions,

                // Arguments when the user taps body of toast
                Launch = new QueryString()
                    {
                        { "action", "viewConversation" },
                        { "conversationId", conversationId.ToString() }

                    }.ToString()
            };

            // And create the toast notification
            var toast = new ToastNotification(toastContent.GetXml());

            toast.ExpirationTime = System.DateTime.Now.AddDays(2);
            toast.Tag = "18365";
            toast.Group = "wallPosts";

        }
    }
}

The system not work and return System.NullReferenceException: 'Object reference not set to an instance of an object.'

image

We want send local notify to windows user, u can help ? 🙌

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

github_iconTop Results From Across the Web

Android Notifications Not Showing Up? 10 Fixes You Can Try
Not seeing notifications show up on your Android phone? Try these fixes to get Android notifications working again.
Read more >
How to Fix Notifications Not Showing up on Android
When notifications aren't showing up on your Android, it's frustrating. These are common fixes that can get your notifications working again.
Read more >
Android notification is not showing
The OP is using Notification.Builder , not NotificationCompat.Builder , like you are suggesting. Just because there is a compatibility library ...
Read more >
How to Fix Notifications Not Working on iPhone and iPad
6️⃣ Go to Settings > Notifications > Tap the app without alerts > Turn off Allow Notifications.
Read more >
I'm not getting notifications on my watch - Android
Try to restart your phone and your watch · On your Android phone, open the Settings app Settings . · Tap Apps and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found