Skip to content

freedesktop.org's D-Bus implementation and wrapper for org.freedesktop.Notifications interface, written in Java.

License

Notifications You must be signed in to change notification settings

catita/java-notify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

java-notify

freedesktop.org's D-Bus implementation and wrapper for org.freedesktop.Notifications interface, written in Java.

Example client usage

Code:

import fd.notify.Notification;

Notification notification = new Notification("Hello!", "I just wanted to say hello :)");
notification.setUrgency(Notification.UrgencyCritical);
notification.send();

Result:

Notification

Example server implementation

package fd.notify;

import java.io.IOException;

public class ListenerImpl extends NotificationListener {

    public static void main(String[] args) throws IOException {
        NotificationServer server = new NotificationServer("ConsoleNotifications", "Sheidy", "1.0");
        server.setListener(new ListenerImpl());
        server.connect();

        Runtime.getRuntime().addShutdownHook(new Thread(() -> server.disconnect()));
    }

    private int notificationNumber = 0;

    @Override
    public int handleNotificaton(NotificationRequest req) {
        System.out.println(req.toString());

        int toReturn = req.getReplacesId();

        if (toReturn == 0) {
            toReturn = ++notificationNumber;
        }

        try {
            return toReturn;
        } finally {
            // this server is not interactive,
            // this is to avoid the sender
            // to wait for an user interaction
            closeNotificaton(toReturn);
        }
    }

    @Override
    public void closeNotificaton(int id) {
        // emit NotificationClosed signal
        notificationClosed(id, ClosedExpired);
    }
}

About

freedesktop.org's D-Bus implementation and wrapper for org.freedesktop.Notifications interface, written in Java.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages