Windows 10 notification blank icon

The java application displays an icon on the taskbar using code that looks something like this:

Toolkit mainToolkit = Toolkit.getDefaultToolkit(); SystemTray mainTray = SystemTray.getSystemTray(); Image trayIconImage = mainToolkit.createImage(getClass().getResource(resourcePath)); TrayIcon mainTrayIcon = new TrayIcon(trayIconImage); mainTray.add(mainTrayIcon); 

Sometimes I change this icon as follows:

 Image newImage = mainToolkit.createImage(getClass().getResource(otherPath)); mainTrayIcon.setImage(newImage); 

From time to time, my application needs to show some kind of notification (using the message about the balloon from its tray icon):

 mainTrayIcon.displayMessage(someCaption, msg, TrayIcon.MessageType.NONE); 

All this code is actually somehow simplified, but perfectly understands this functionality.

So, everything is fine in Windows 7. But it turns out that in Windows 10 it shows in different ways. The notification has an icon shown on the left. This is usually the icon of the current application in the application, but sometimes it is simply empty:

Erroneous notification

A blank icon is displayed in the upper red circle (in the notification), which sometimes appears instead of the icon for my application (in the lower red circle on the system tray). I have no idea why this is happening. All I know is that it only happens when the application icon and the notification icon change before the first notification (which always shows its icon correctly) disappears. If a notification is displayed, then fades / closes manually. AND ONLY the icon icon in the app and change notifications. The following notification (with a new message that has just been installed) will correctly display in the application.

+6
source share
1 answer

Just stumbled upon this problem and found the right solution:

mainTrayIcon.setImageAutoSize(true);

Here you can send a notification in Windows:

 public static void sendNotification(String title, String subtitle, String pathToIcon) { SystemTray mainTray = SystemTray.getSystemTray(); Image trayIconImage = Toolkit.getDefaultToolkit().getImage(pathToIcon); TrayIcon mainTrayIcon = new TrayIcon(trayIconImage); mainTrayIcon.setImageAutoSize(true); try { mainTray.add(mainTrayIcon); mainTrayIcon.displayMessage(title, subtitle, TrayIcon.MessageType.NONE); } catch (Exception e) { e.printStackTrace(); } } 

Call sendNotification("Title", "Subtitle", "icons/icon-128.png"); shows

Working notice

0
source

All Articles