JDK-8323821 : Use toast notifications on Windows 11
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: java.awt
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2024-01-12
  • Updated: 2024-08-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Relates :  
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Windows 11 
JDK 21.0.1

A DESCRIPTION OF THE PROBLEM :
Notification vanishes from Windows 11 notification center after a few seconds no matter what Windows settings are in use.
With previous version of Windows notifications stuck in the Windows Notification Center forever until cancelled. 

This problem happens on Windows 11 only and not on previous versions of Windows like Win 10.

The problem happen because Java uses a 25 years old API for notifications (Shell_NotifyIcon API) that does not work anymore on Windows 11.
That API was meant for Windows 95, not for Windows 11.

Windows 11 notifications should use the new API (ToastNotification API).
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

Java 21 is not able to correctly send a Notification to Windows, 
this is a urgent bug to me because OS notifications are very crucial this days and every modern languages supports it.

Me and others reported this as an issue:
https://bugs.java.com/bugdatabase/view_bug?bug_id=8310352
but someone from Oracle closed the issue by saying that this is not a JDK issue but a Microsoft one.

I wrote to Microsoft and they suggested to use the new notification APIs meant for Windows 11 since the old APIs are unsupported on newer OS.

If you don't want to consider it as a bug, no problem,
but Java is not able to send an OS notification to Windows 11 currently.

I hope that someone will work on it as a feature request.
Comments
There's a similar enhancement request JDK-8266423 which talks about both macOS and Windows. Related bug reports: JDK-8310352 and JDK-8315647, the latter is closed as duplicate of the former. The discussion thread on client-libs-dev: https://mail.openjdk.org/pipermail/client-libs-dev/2024-January/016815.html Previous iteration of the discussion: https://mail.openjdk.org/pipermail/client-libs-dev/2023-August/014556.html
17-01-2024

> Windows 11 notifications should use the new API (ToastNotification API). [~aivanov] noted off-line that this may not be equivalent " I have an impression that the app must have an icon in the Start menu for these notifications to work. If it's the case, it won't play nicely with Java which is an app platform and the same executable, java.exe or javaw.exe, can run multiple applications. The notifications should be displayable even if there's no icon to a Java launcher in the Start menu. Java uses Win32 APIs only." We should confirm this and enumerate the options since it implies that we can't simply re-implement to use toast.
17-01-2024

> This problem happens on Windows 11 only and not on previous versions of Windows like Win 10. Acccording to Microsoft support, this statement is incorrect. Windows 10 was the exception, not the rule. They were ephemeral on every version of Windows from Window 95 through 8.1 and again on Windows 11.
17-01-2024