notify.osd.OsdNotifier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-to-OS-notify Show documentation
Show all versions of java-to-OS-notify Show documentation
Java to Operating System Notification
package notify.osd;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import notify.MessageType;
import notify.Notifier;
import notify.UnableToNotifyException;
/**
* Notify OSD Implementation for Ubuntu
* Requires notify-send commmand
* sudo apt-get install libnotify-bin
* http://archive.ubuntu.com/ubuntu/pool/universe/libn/libnotify4/libnotify- bin_0.7.2-0ubuntu2_amd64.deb
*
* http://www.barregren.se/blog/pop-notification-command-line
*
*
* @author francois wauquier
*
*/
public class OsdNotifier implements Notifier {
@Override
public boolean isSupported() {
try {
return Runtime.getRuntime().exec("notify-send --help > nil").waitFor() == 0;
} catch (Exception e) {
return false;
}
}
@Override
public void notify(MessageType messageType, String title, String message) {
List command = new ArrayList();
command.add("notify-send");
switch (messageType) {
case NONE:
break;
default:
command.add("-i");
command.add("gtk-dialog-" + messageType.name().toLowerCase());
}
command.add(title);
command.add(message);
try {
Runtime.getRuntime().exec(command.toArray(new String[command.size()]));
} catch (IOException e) {
throw new UnableToNotifyException("Unable to notify with Notify OSD", e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy