Windows 11: Notifications vanishes after few seconds.

Aleksei Ivanov alexey.ivanov at oracle.com
Wed Jan 17 18:30:56 UTC 2024


Hi Davide,

The enhancement you submitted is now available in JBS:

https://bugs.openjdk.org/browse/JDK-8323821
Use toast notifications on Windows 11

I updated the subject so that it sounds like an enhancement rather than 
a bug.

JDK-8323821 is more specific than 
https://bugs.openjdk.org/browse/JDK-8266423 which talks about both macOS 
and Windows.


If you have ideas on how to implement toast notifications for JDK, feel 
free to discuss the ideas further. Contributions are welcome.

-- 
Regards,
Alexey

On 2024-01-12 11:40, Davide Perini wrote:
> I wrote to Microsoft and they suggested to use the New APIs 
> (ToastNotification) meant for the purpose
>
> 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
>
> Shell_NotifyIcon API is clearly unsupported after 25/30 years on a 
> modern OS.
>
> If you are a Java programmer, you can't send an OS notification.
>
> OS Notifications are very crucial to most apps this days,
> I can't imagine how Java can overlook it.
>
> Since you don't accept it as a bug (Oracle is closing all the bug 
> reports from people on this),
> I opened a feature request on this in the hope that someone wise will 
> look at it.
>
> Kind Regards,
> Davide
>
>
> Il 08/01/2024 22:05, Davide Perini ha scritto:
>> Thanks for the explanation Aleksei
>> but can you explain me what is the OpenJDK direction please?
>>
>> Suppose that you have a feature like this one, a simple notifications.
>> Java worked well with Windows notifications until Win10,
>> then Microsoft changed the APIs for notifications in Win11.
>>
>> Isn't OpenJDK supposed to adapt to the new Windows APIs?
>>
>> Does OpenJDK supports Windows 11 or not?
>>
>> It's a little "weird" to close an issue by saying that Java uses the 
>> same way to do the same thing since Windows 95
>> and that it's a Microsoft problem if they changed the way to send 
>> notifications to the OS.
>>
>> Java should support Microsoft Windows, it isn't Microsoft Windows 
>> that should support Java,
>> isn't it?
>>
>> Other languages adapted their APIs for the new notifications system, 
>> like everyone should expect from a modern language,
>> after 2 years from the release of Win 11,
>> Oracle says that it worked since Windows 95, so it is ok to have a 
>> broken API in JDK because it worked before, they are the ones who 
>> broke it (Microsoft).
>>
>> Does Java offers a correct way to send Notifications in Win10? 
>> Answer: Yes
>> Does Java offers a correct way to send Notifications in Win11? Answer: No
>> Does other languages offers a correct way to send Notifications in 
>> Win11? Answer: Yes
>> Does current JDK APIs works as expected in Win11?
>> Answer: No because JDK uses an old API born with Win95 (30 years ago 
>> + or -) with a new OS born in 2021, this results in an unexcpected 
>> behaviour that doesn't work as supposed initially by the API.
>>
>> In the bug report you wrote:
>> "I can't see what Java can do to change the behaviour."
>>
>> The answer is:
>> "By implementing the correct API for the correct OS".
>>
>>
>> Java is currently not able to correctly send a Notification in 
>> Windows 11.
>>
>>
>> I see a bug there, if you don't see it,
>> I'm pretty worried of the new JDK direction.
>>
>> Thanks
>> Davide
>>
>>
>> Il 08/01/2024 20:55, Aleksei Ivanov ha scritto:
>>> On 2024-01-08 19:30, Davide Perini wrote:
>>>> Thanks for the Answer Aleksei,
>>>> I have a lot of Windows apps that uses notifications without problems.
>>>>
>>>> even a simple python program like this works correctly.
>>>> from win11toastimport toast
>>>>
>>>> toast('Hello','Click to run python script')
>>>
>>> Python could use newer WinRT APIs [6], in particular 
>>> ToastNotification class [7] which provide richer interface for the 
>>> toast notifications. The package name ‘toast’ hints it uses the 
>>> newer APIs.
>>>
>>>> is it possible that Microsoft changed the way how to create 
>>>> Notifications in Windows 11 and Java still uses the way it worked 
>>>> in Windows 7?
>>>
>>> Perhaps, Microsoft changed how they handle notifications in Windows 
>>> 11. In Windows 10, the notifications created with a Java app remain 
>>> in Action / Notification centre.
>>>
>>> Java uses Shell_NotifyIcon [8] function that has been available 
>>> since Windows 95.
>>>
>>> -- 
>>> Regards,
>>> Alexey
>>>
>>> [6] https://learn.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/
>>> [7] 
>>> https://learn.microsoft.com/en-us/uwp/api/windows.ui.notifications.toastnotification?view=winrt-22621
>>> [8] 
>>> https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shell_notifyiconw
>>>
>>>>
>>>> Thanks
>>>> Davide
>>>>
>>>>
>>>>
>>>> Il 08/01/2024 17:59, Aleksei Ivanov ha scritto:
>>>>> Hi Davide,
>>>>>
>>>>> The bug that you reported has been moved to JDK project in JBS, 
>>>>> you can view it as JDK-8315647 [1]. You should've received a link 
>>>>> to it.
>>>>>
>>>>>> Is there a way to workaround this JDK bug?
>>>>>> I opened a bug report months ago but no one answered. 
>>>>>
>>>>> What kind of answer did you expect to receive?
>>>>>
>>>>> You already asked this question on this mailing list in August 
>>>>> [2]. I replied to your question [3]. Nothing has changed since 
>>>>> August. It is not a bug in Java because a native Win32 app behaves 
>>>>> the same way.
>>>>>
>>>>> I compiled and tested the sample [4], it behaves in Windows 11 as 
>>>>> Java does: the displayed balloon notification does not go to 
>>>>> notification centre. However, if I open notification centre while 
>>>>> the balloon is displayed, it remains there. If I disable "Show 
>>>>> notification banners" and leave "Show notifications in 
>>>>> notification centre" enabled, the balloon goes directly to 
>>>>> notification centre without displaying a banner.
>>>>>
>>>>> You can compile and test the sample too:
>>>>>
>>>>> 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.
>>>>>
>>>>> If required, I can attach the compiled version of the application.
>>>>>
>>>>>
>>>>> I have closed JDK-8315647 as duplicate of JDK-8310352 [5].
>>>>>
>>>>
>>>
>>
>



More information about the client-libs-dev mailing list