How to raise user notifications in Ubuntu using Java code?


You can use java-gnome, a java binding for GTK and GNOME to display notify-osd notifications. You'll need to install the library first:

sudo apt-get install libjava-gnome-java libjava-gnome-java-doc   

Here is a quick example:

import org.gnome.gtk.Gtk;
import org.gnome.notify.Notification;
import org.gnome.notify.Notify;

public class notifyTest {
    public static void main(String[] args) {  

        Gtk.init(args); // initialize Gtk
        Notify.init("Program Name"); // initalize the notification system  

        Notification myNotification = new Notification("Hello world!", "This is an example notification.", "dialog-information"); // create the notification object
        myNotification.show(); // show the notification  



The general format for a notification is this:

Notification someName = new Notification("Summary", "Body", "Icon")  

Both the body and icon fields can be null, but there must be a summary. For a list of icons you can use by default check the Notify-OSD page of the Ubuntu Wiki.

You then call:


To display the notification. For more information see the java-gnome Notify and Notification doc pages.

Note: You must have both Gtk and Notify initialized before you can send any notifications.

  • You should do a selfanswered in SO ;) – Braiam Dec 28 '13 at 0:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.