Quickstart: Sending a local toast notification and handling activations (Windows 10)


Content moved

Please see the article on docs.microsoft.com for the latest documentation.

Comments (38)

  1. pkz says:

    I have a Windows 8.1 Universal app. I assume this will only work if the app is running on Windows 10. But will it cause issues if the app runs on Windows 8.1?

  2. leixu2046 says:

    @pkz Thanks for the question!

    If you are wondering if the new Windows 10 UWP app can run on Windows 8.1 platform, the answer is no unfortunately.

    If you are wondering if you can use the adaptive toast templates in a Windows 8.1 app running on Windows 10 OS, the answer is partially – you can use the adaptive templates (flexible visuals), but only part of the interactive features – you can do protocol launch, but not foreground activation or background activation since Windows 8.1 SDK doesn't have the new activation kind and the new background trigger.

  3. Suresh says:

    I have a windows 8 app, notifications enabled for my app. and its working great in windows 8 and windows 8.1 and Windows 10 machines.

    The only problem i am facing is when user taps on toast notification based on the launch arguments (which are present in toast can be read from LaunchActivatedEventArgs of Onlaunched event) I am redirecting the user to specific page. This functionality is working fine in Windows 8,8.1 machines but not working in windows 10 machine. Could you please suggest me what should i do ?

  4. andrewbares7 says:

    @Suresh – See our conversation on the Adaptive and Interactive Toasts documentation article

  5. Suresh says:

    @andrewbares7 – sorry for the late reply and thanks for pointing me. am going to see those comments now.

  6. Pawa says:

    Hi! You say "Note: the only thing your app wouldn’t be notified for, is a local toast being popped/added, since it is not necessary to notify your app client about something it just did.". That makes sense, but what about Scheduled Toast Notifications? Is there any way to be notified when a scheduled toast I issued fires?

  7. andrewbares7 says:

    @Pawa – even for scheduled toasts, that's something your local app knows about, so we choose not to tell you about something your app already knows about.

    What scenario are you trying to accomplish with this?

  8. Pawa says:

    @andrewbares7 – Thanks for your reply! I am doing it in foreground, but I couldn't find a way to do it in background. I have since solved my issue in another way, though.

    I'm developing an app for repetitive reminders, like "take a break every hour". I wanted to know in background when a notification is delivered so I could clear previous notifications and avoid a pile-up in the action bar.

    I have since discovered that by giving each notification the same Group and Tag effectively causes them to replace each other, which solves my issue. I can still compare them by storing unique Ids, so for my purpose everything is working.

  9. andrewbares7 says:

    @Pawa – Ah yes, Group and Tag sounds like the correct way to make that scenario work! Glad to hear you got it working!

    Note that you also can set the ExpirationTime on your toasts, so that they automatically disappear after a certain amount of time. Useful if a toast is no longer relevant after a certain point in time.

  10. ShenghuaChen says:

    Hello @leixu2046 and @andrewbares7. Can I send Toast Notifications from Win32 application? Since I didn't find any Win32 API for Toast Notifications, but I want to implement it with C++ in my Win32 application.Thank you.

  11. andrewbares7 says:

    @Shenghua – Lei is working on publishing a post explaining how to send toasts from Win32. He'll hopefully have that post up by the end of this week.

  12. leixu2046 says:

    @ShenghuaChen Hi Shenghua, check out this blog post on how win32 apps sends and handles toast notifications:

    blogs.msdn.com/…/quickstart-handling-toast-activations-from-win32-apps-in-windows-10.aspx

  13. ShenghuaChen says:

    Really thank you @andrewbares7 and @leixu2046, it's very helpful to me.

  14. heroichippo1 says:

    How can I launch this app from command line after its been built and deployed? Trying to create a batch file that can send a notification when my Unity build is finished, so all i need is a local notification, don't really care about all the different actions when using it, its just for my own personal use.

    All i can find online is using start.exe to launch settings programs etc, but nowhere do i see anything about how to launch a custom built app from start command.

  15. andrewbares7 says:

    @heroichippo1 – Sorry, our team isn't responsible for command line launching. We know nothing about that and can't help you. Try asking on MSDN forums.

  16. Chourouk says:

    These are 2 examples of samples using toast notifications and tile notifications:

    code.msdn.microsoft.com/Tile-notifications-in-e217d57f

    code.msdn.microsoft.com/Toast-notifications-in-17c55610

    Best of luck!

  17. Rick says:

    Can’t clip this code or in some cases even read it. Is it formated for Edge?

    1. andrewbares7 says:

      Hey Rick, sorry for the issues with the code snippets. MSDN Blogs migrated to WordPress recently, and it seemed to have messed up a few things. I’ve fixed the code snippets, they should display and copy correctly now!

  18. Rocky says:

    Can background task works with Desktop application too? I am not planning to have my application available on app store or not creating a universal windows type of project. This is regular console or desktop application and will be closed after notification is generated, How can I implement chasing the actions?

  19. Ramkiran says:

    I have an Existing WinRT 8.1 App. All Toast Notifications works beautifully on Win8.1 OS.

    No when I tried to run the same 8.1 app on Win10 OS, I don’t see any notifications. Do I need to do something extra?

    Note: Action center is enabled and I have not restricted any App specific notifications in notification Center.

    1. andrewbares7 says:

      Hey Ramkiran, 8.1 apps should work fine on 10. Could you give us more info?
      (1) Desktop or Mobile?
      (2) What build are you running? Type “winver” in Start.
      (3) What’s your app’s name? Can we install it from the Store and try it out?
      (4) Are you using push notifications, or local notifications?
      (5) Which toast template are you using? ToastText01, etc…

      1. Ramkiran says:

        1. It is a Win8.1 Phone App running on Win10 OS Device.
        2. version is 1511 and Build is 10586.17.
        3. No you cannot download from Store.
        4. These are Local Notifications.
        5. ToastTemplateType.ToastText01

        More Information below – This doesn’t work with Assigned Access – Associate Persona. It works with Admin Persona.
        It has something to do with ToastCapable=”true” property in Manifest file. Below are my observations….
        1) First Time run ever with Toast Capable to true – No Toasts
        2) Seconds time run without Toast capability – Displayed Toasts.
        3) Third time run back with Toast Capable to true – Displayed Toasts.
        ->> Not sure why its behaving strange though.

        1. andrewbares7 says:

          Hmm, well you definitely need to have ToastCapable set to true in the manifest since 8.1 required that, otherwise your toasts won’t work in 8.1 (in 10, we stopped requiring the ToastCapable flag).

          I’ll see if I can repro the issue, but just FYI, we haven’t heard any other reports of toasts not working for 8.1 RT phone apps running on 10.

          1. Ramkiran says:

            I got it working with adding AUMID to the toast capable apps in Lockdown file.

  20. Hamza says:

    Hi everybody!
    Why there is no “ExpirationTime” attribute for the ScheduledToastNotification, In MSDN it says it has, in VS2015 Update 3 it says no. Can’t figure it out.

    1. andrewbares7 says:

      Hey Hamza, sorry for the extremely slow response. ScheduledToastNotification unfortunately is missing the ExpirationTime property as you noticed. Thank you for letting us know that you would use this property, that helps us prioritize for future releases!

      We’ve updated the MSDN documentation that incorrectly claimed ScheduledToastNotification supported expiration time. Thanks!

  21. Jay343 says:

    Is there a way to subscribe to all toast notifications? Specifically, if there is a commercial app running that pops toast for certain events, and I wish to write a service that waits for specific notifications from that app, which then performs a function based on the content of the notification, is that a supported scenario?

  22. lostmsu says:

    Is there a way to show Windows 8.x notifications on Windows 8.x, but show interactive ones on Windows 10? Currently, I am using custom template, and on Windows 8.x it does not show up at all. I want to be able to detect that and show Windows 8.x notification instead.

  23. Srinivasan says:

    Is there any way to notify my app for local toast?

  24. B G Turner says:

    I have a UWP app I am developing, I pop up toasts from a background task on a specified interval, this works perfectly.
    However when I click the toast my App loads up but never gets past the loading screen. I worked out that I need to handle the OnActivated override which I have done but if I breakpoint inside this event it is never triggered and my app never gets beyond the loading screen. Is there some reason this even would not trigger? The notification was created in c# using the community toolkit:
    Microsoft.Toolkit.Uwp.Notifications

    1. leixu2046 says:

      Can you please share your Windows version information, and possibly a code snippet of how you construct your toast? Please feel free to reach out at lex@microsoft.com and we will be able to help further.

      1. B G Turner says:

        Hi, sorry this was me being a bit of an idiot, I finally realised what was going on after an hour or two of flapping.
        As I was opening the app from a Toast which was created in a background task the App was not actually being debugged in Visual Studio which obviously meant that the OnActivated break point as not being hit. So I went ahead and actually added the code and low and behold it worked.
        So mostly a schoolboy error! Out of interest, is there any way to attach a debugger to an App on launch like that? I have done it while a program is running but not automatically on launch. Its not something I have ever had to do before…

  25. Zal says:

    Not sure if anyone is reading this but I will ask anyway… is it possible to somehow inject into the system code for dismiss button or do I have to create a custom dismiss button if I want to do some things (like removing a line in a file) when the user clicks dismiss? Thanks.

    1. andrewbares7 says:

      Hey Zal!

      So you want a toast that, when the user clicks a button on your toast, your code modifies a file (removing a line in the file)? You would have to use a background activation button for that, which activates your background task to modify that file.

  26. Justin Hagerty says:

    I wanted to send a toast notification from a C# program with out using a UWP app. It took a lot of research. I am newish to C# and I have found a solution.

    https://pastebin.com/QrYa47Qu

  27. Dev says:

    I just tried this API and it works very poorly. There’s bugs when I run this in embedded mode.

Skip to main content