Using OS X 10.8 Notification Center (NSUserNotification) with Java

耗尽温柔 提交于 2019-12-10 15:58:06

问题


I'm struggling with the notification center in OS X 10.8. I wrote a wrapper to provide Java access to the NSUserNotification and NSUserNotificationCenter classes via JNA, however the functionality is limited. I am able to send a notification and it will display as long as the .jar is being run from an .app bundle via JavaApplicationStub. However, the line below is always logged to the console when the the notification style is set to "Alerts":

11/29/12 8:37:12.537 PM usernoted[162]: Failed to validate application at (null) -67061

Next, clicking the notification results in the following being logged to the console:

11/29/12 8:38:15.291 PM usernoted[162]: Cannot find originating application to launch for event action.  file://localhost/Users/geoffodonnell/Projects/bin/GuiTest.app/ is not the same app as the one that sent the original notification.

I did provide the NSUserNotificationCenter class with a delegate, however those methods only get run when the .jar is executed outside of a bundle. Naturally, this defeats the purpose since the notification will never be displayed.

Can anyone provide any insight into the two errors above?

I am wondering if the JavaApplicationStub is getting in the way, however I'm in the dark when it comes to how exactly a typical application would respond the notification center events.


回答1:


This issue is solved by updating to JDK 7u10 (Developer Preview) located here,

http://jdk7.java.net/download.html

And using the appbundler tool described here,

http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html

to create your application bundle. This tool creates an application bundle with a different executable stub file, so perhaps JavaApplicationStub (and/or JRE 1.6) was the culprit.



来源:https://stackoverflow.com/questions/13638092/using-os-x-10-8-notification-center-nsusernotification-with-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!