Guide set but notification not work
See original GitHub issueHi 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.'
We want send local notify to windows user, u can help ? 🙌
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Try to provide an applicationId in CreateToastNotifier(). Hopefully this solves the issue.
https://stackoverflow.com/questions/32214716/showing-a-windows-10-toast-notification
Official doc: https://docs.microsoft.com/en-us/uwp/api/windows.ui.notifications.toastnotificationmanager.createtoastnotifier?view=winrt-19041#Windows_UI_Notifications_ToastNotificationManager_CreateToastNotifier_System_String_
@tfennel might know