Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using OS X 10.8 Notification Center (NSUserNotification) with Java

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.

like image 431
Geoff Avatar asked Nov 04 '22 09:11

Geoff


1 Answers

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.

like image 76
Geoff Avatar answered Nov 15 '22 00:11

Geoff