Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How to raise user notifications in Ubuntu using Java code?

share|improve this question
2  
This is more of a coding question. I found this on SO: stackoverflow.com/questions/8987485/… –  Rinzwind Sep 20 '13 at 13:17

1 Answer 1

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:

someName.show();  

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.

share|improve this answer
    
You should do a selfanswered in SO ;) –  Braiam Dec 28 '13 at 0:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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