JDK-8310352 : Notification no longer appears in the Windows 11 notification center
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 17
  • Priority: P4
  • Status: Closed
  • Resolution: External
  • OS: windows
  • CPU: x86_64
  • Submitted: 2023-06-14
  • Updated: 2024-04-23
  • Resolved: 2023-10-02
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
Notification no longer appears in the Windows 11 notification center after automatically disappear.
The notification still appears in the Windows 10 notification center after automatically disappear.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run example.
2. Click button to show notification.
3. Wait until notification disappears automatically.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The notification still appears in notification center.
ACTUAL -
The notification still appears in notification center under Windows 10.
The notification is no longer displayed in the notification center under Windows 11.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;

public class Main {
    public static void main(String[] args) throws Exception {
        var frame = new Frame("Notification Example");
        var button = new Button("Notify");
        frame.add(button);
        var image = new BufferedImage(32, 32, BufferedImage.TYPE_4BYTE_ABGR);
        var trayIcon = new TrayIcon(image);
        SystemTray.getSystemTray().add(trayIcon);

        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                e.getWindow().dispose();
                System.exit(0);
            }
        });
        button.addActionListener(e -> {
            trayIcon.displayMessage("Hello World", "Lorem ipsum", TrayIcon.MessageType.INFO);
        });

        frame.pack();
        frame.setVisible(true);
    }
}

---------- END SOURCE ----------

FREQUENCY : always



Comments
Instructions on how to get and compile Microsoft's NotificationIcon Sample [1][2] (copied from JDK-8315647 for completeness): git clone --filter=blob:none --sparse https://github.com/microsoft/Windows-classic-samples.git windows-samples cd windows-samples git sparse-checkout add Samples/Win7Samples/winui/shell/appshellintegration/NotificationIcon Navigate to the NotificationIcon folder and open NotificationIcon.sln in Visual Studio to compile and run it. [1] https://learn.microsoft.com/en-us/windows/win32/shell/samples-notificationicon [2] https://github.com/microsoft/Windows-classic-samples/tree/main/Samples/Win7Samples/winui/shell/appshellintegration/NotificationIcon
17-01-2024

[~karianna] Newer toast notification APIs are part of WinRT and these notifications are preserved in the notification centre until dismissed explicitly. JDK-8323821 is the enhancement request for using toasts. There's also JDK-8266423.
17-01-2024

Maybe related: Java is using the Shell_NotifyIcon API for the notifications. It might be the case that it should move to the new new APIs for Windows 11 notifications (ToastNotification)? https://learn.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/toast-notifications-overview & https://learn.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/send-local-toast-desktop-cpp-wrl
09-01-2024

Discussion on the mailing list: https://mail.openjdk.org/pipermail/client-libs-dev/2023-August/014556.html
02-10-2023

Based on the above comments, I reopened the bug to close it as External: the problem is in Windows (11). I can't see what Java can do to change the behaviour.
02-10-2023

Windows 11 lists notifications permissions the same way Windows 10 does. The default is on, I verified the option "Show notifications in notification center" is enabled for Java but the notification isn't stored in the notification center. It seems to be a Windows bug. I remember a few months ago there was the opposite bug: notifications from apps for which "Show notifications in notification center" was disabled were still shown in the notification center.
31-08-2023

Windows 11 at least, lists notification permissions for apps under the global setting. So there's the global setting and the per-app setting. Perhaps apps now default to off ?
30-08-2023

Tested with a recent build of mainline development on Windows 10 (Version 22H2). After I click Notify button, a notification is displayed (Notification.png). As soon as it disappears, the notification icon on the taskbar shows 1; if I open the notification center, I see the notification from Java there (Notification in Action Center.png). To display a notification, Java uses Windows Shell API which is available since Windows 95. This API provides no control whether the notification disappears or goes to the Action Center; after all, the Action or Notification center didn't exist until Windows 8. Whether the notification goes to the Action Center or not is control by Notification Settings in Windows. On the "Notification settings for Java.png" screenshot, you see that "Show notifications in action center" is enabled (the setting on the right).
30-08-2023

I run the test on my Windows 11 system (Version 22H2), and the notification from Java doesn't go into the notification center even though it's enabled in Windows Settings.
30-08-2023

Checked with attached testcase in Windows 11, Issue is not reproducible<attached screenshot> Test Result =========== 8u371:Pass 11.0.19: Pass 17.0.7: Pass 20.0.1: Pass 21ea27: Pass Note: Make Sure Notifications Are Enabled
20-06-2023