Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notifications on Windows 10 using desktop app

I got a Windows Forms project in C# with a NotifyIcon. I'm using the following code to display a balloon notification:

notifyIcon.ShowBalloonTip(1000, "title", "text", ToolTipIcon.Info);

This was working fine until Windows 8.1. Now I've installed the Windows 10 Preview and the balloon notification doesn't show up anymore.

I guess that all notifications are moved to the Windows 8 style toast notifications and the balloon notifications are completely removed (because I haven't seen a single balloon notification yet and many more toast notifications), however I haven't found an official source for this yet.

The problem is that my application is simply a single .exe file and so it doesn't have an installer or shortcut. According to this page an installer that creates a shortcut is needed for toast notifications to work.

How can I show notifications (I don't care if it's a balloon or toast notification) in Windows 10 without any shortcuts or installers?

like image 505
Louis Matthijssen Avatar asked Oct 04 '14 11:10

Louis Matthijssen


People also ask

How to turn on notifications in Windows 10?

1 Open the Settings app . To do so, either click the Settings icon in the Start menu or use Windows logo and I hotkey. 2 In the Settings app, click System, and then click Notifications and actions. 3 First, in the Notifications section, make sure that Get notifications from apps and other senders option is turned on. ... More items...

How do I manage notifications in different operating systems?

Manage notifications in different operating systems: 1 Windows 10: Select Start > Settings > System > Notifications & actions > Focus assist 2 MacOS: Select Apple menu > System Preferences > Notifications > Do Not Disturb 3 Android: Select your phone’s Settings app > Apps & Notifications>

Can I disable Desktop notifications for all apps?

While you can disable desktop notifications entirely (for all apps), you might want to disable notifications for apps that often show notifications or for apps that are not so important. For instance, you might want to disable Twitter and Facebook notifications. You can always open up the app to see all the notifications.

How do I know if my apps display notifications?

Default apps as well as apps installed from Windows Store display notifications. You see a desktop notification when you receive an email message, for instance. If you have installed all social media apps, you probably often see desktop notifications.


1 Answers

I used this thread to help make this code - I am sharing my success.

warning I am kind of new to C# so my code probably sucks- but it does work and is pretty simplistic and that's more than I can say for most solutions I have found

Also I was having a hell of a time getting the xml document to read. I was fighting with System.xml (I think) and Windows.Data.Dom.Xml (also not completely sure). In the end I settled on making them hard coded strings for my example file and used a switch statement to switch between them. I have found a ton of people, looking for the solution that I have come up with, on stack overflow. It seems use of the toast notification system with console or background applications would be super useful, and the documentation that surrounds the toast notification system with windows applications all suggest that it needs to be used with an application. The Action Center is super useful for notifications vrs the NotificationTray/NotifyIcon route. I have not found a full solution anywhere else on the web. Here is example code.

/*
At first you need to declare that your program will be using winRT libraries:
1. Right click on your yourProject, select Unload Project
2. Right click on your youProject(unavailable) and click Edit yourProject.csproj
3. Add a new property group:<TargetPlatformVersion>8.0</TargetPlatformVersion>
4. Reload project
5. Add referece Windows from Windows > Core
*/
using System;
using Windows.Data.Xml.Dom;
using Windows.Storage;
using Windows.Storage.Streams;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Notifications;

namespace ConsoleApplication6
{
    public class NewToastNotification
    {
        public NewToastNotification(string input, int type)
        {
            string NotificationTextThing = input;
            string Toast = "";
            switch (type)
            {
                case 1:
                    {
                        //Basic Toast
                        Toast = "<toast><visual><binding template=\"ToastImageAndText01\"><text id = \"1\" >";
                        Toast += NotificationTextThing;
                        Toast += "</text></binding></visual></toast>";
                        break;
                    }
                default:
                    {
                        Toast = "<toast><visual><binding template=\"ToastImageAndText01\"><text id = \"1\" >";
                        Toast += "Default Text String";
                        Toast += "</text></binding></visual></toast>";
                        break;
                    }
            }
            XmlDocument tileXml = new XmlDocument();
            tileXml.LoadXml(Toast);
            var toast = new ToastNotification(tileXml);
            ToastNotificationManager.CreateToastNotifier("New Toast Thing").Show(toast);
        }
}

    class Program
    {
        static void Main(string[] args)
        {
            NewToastNotification Window = new NewToastNotification("Yes",1);


        }
    }
}
like image 141
wheelsmanx Avatar answered Oct 01 '22 20:10

wheelsmanx