Class Notification
- All Implemented Interfaces:
Proxy
GNotification is a mechanism for creating a notification to be shown
to the user — typically as a pop-up notification presented by the
desktop environment shell.
The key difference between GNotification and other similar APIs is
that, if supported by the desktop environment, notifications sent
with GNotification will persist after the application has exited,
and even across system reboots.
Since the user may click on a notification while the application is
not running, applications using GNotification should be able to be
started as a D-Bus service, using Application.
In order for GNotification to work, the application must have installed
a .desktop file. For example:
[Desktop Entry]
Name=Test Application
Comment=Description of what Test Application does
Exec=gnome-test-application
Icon=org.gnome.TestApplication
Terminal=false
Type=Application
Categories=GNOME;GTK;TestApplication Category;
StartupNotify=true
DBusActivatable=true
X-GNOME-UsesNotifications=true
The X-GNOME-UsesNotifications key indicates to GNOME Control Center
that this application uses notifications, so it can be listed in the
Control Center’s ‘Notifications’ panel.
The .desktop file must be named as org.gnome.TestApplication.desktop,
where org.gnome.TestApplication is the ID passed to
Application().
User interaction with a notification (either the default action, or
buttons) must be associated with actions on the application (ie:
app. actions). It is not possible to route user interaction
through the notification itself, because the object will not exist if
the application is autostarted as a result of a notification being
clicked.
A notification can be sent with Application.sendNotification(java.lang.String, org.gnome.gio.Notification).
- Since:
- 2.40
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classNotification.Builder<B extends Notification.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new Notification.Notification(MemorySegment address) Create a Notification proxy instance for the provided memory address.Notification(String title) Creates a newGNotificationwithtitleas its title. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a button to this Notification that activates the action indetailedActionwhen clicked.voidaddButtonWithTarget(String label, String action, @Nullable Variant target) Adds a button to this Notification that activatesactionwhen clicked.protected NotificationasParent()Returns this instance as if it were its parent type.static Notification.Builder<? extends Notification.Builder> builder()ANotification.Builderobject constructs aNotificationwith the specified properties.static @Nullable TypegetType()Get the GType of the Notification classvoidSets the body of this Notification tobody.voidsetCategory(@Nullable String category) Sets the type of this Notification tocategory.Categories have a main type likeemail,imordeviceand can have a detail separated by a., e.g.voidsetDefaultAction(String detailedAction) Sets the default action of this Notification todetailedAction.This action is activated when the notification is clicked on.voidsetDefaultActionAndTarget(String action, @Nullable Variant target) Sets the default action of this Notification toaction.This action is activated when the notification is clicked on.voidSets the icon of this Notification toicon.voidsetPriority(NotificationPriority priority) Sets the priority of this Notification topriority.SeeGNotificationPriorityfor possible values.voidSets the title of this Notification totitle.voidsetUrgent(boolean urgent) Deprecated.Since 2.42, this has been deprecated in favour of g_notification_set_priority().Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Notification
Create a Notification proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
Notification
Creates a newGNotificationwithtitleas its title.After populating
notificationwith more details, it can be sent to the desktop shell with g_application_send_notification(). Changing any properties after this call will not have any effect until resendingnotification.- Parameters:
title- the title of the notification- Since:
- 2.40
-
Notification
public Notification()Creates a new Notification.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName(). This will call the native function pointer of this virtual method in the typeclass of the parent type. -
addButton
Adds a button to this Notification that activates the action indetailedActionwhen clicked. That action must be an application-wide action (starting with "app."). IfdetailedActioncontains a target, the action will be activated with that target as its parameter.See g_action_parse_detailed_name() for a description of the format for
detailedAction.- Parameters:
label- label of the buttondetailedAction- a detailed action name- Since:
- 2.40
-
addButtonWithTarget
Adds a button to this Notification that activatesactionwhen clicked.actionmust be an application-wide action (it must start with "app.").If
targetis non-null,actionwill be activated withtargetas its parameter.- Parameters:
label- label of the buttonaction- an action nametarget- aGVariantto use asaction'sparameter, ornull- Since:
- 2.40
-
setBody
Sets the body of this Notification tobody.- Parameters:
body- the new body fornotification,ornull- Since:
- 2.40
-
setCategory
Sets the type of this Notification tocategory.Categories have a main type likeemail,imordeviceand can have a detail separated by a., e.g.im.receivedoremail.arrived. Setting the category helps the notification server to select proper feedback to the user.Standard categories are listed in the specification.
- Parameters:
category- the category fornotification,ornullfor no category- Since:
- 2.70
-
setDefaultAction
Sets the default action of this Notification todetailedAction.This action is activated when the notification is clicked on.The action in
detailedActionmust be an application-wide action (it must start with "app."). IfdetailedActioncontains a target, the given action will be activated with that target as its parameter. See g_action_parse_detailed_name() for a description of the format fordetailedAction.When no default action is set, the application that the notification was sent on is activated.
- Parameters:
detailedAction- a detailed action name- Since:
- 2.40
-
setDefaultActionAndTarget
Sets the default action of this Notification toaction.This action is activated when the notification is clicked on. It must be an application-wide action (start with "app.").If
targetis non-null,actionwill be activated withtargetas its parameter. Iftargetis floating, it will be consumed.When no default action is set, the application that the notification was sent on is activated.
- Parameters:
action- an action nametarget- aGVariantto use asaction'sparameter, ornull- Since:
- 2.40
-
setIcon
Sets the icon of this Notification toicon.- Parameters:
icon- the icon to be shown innotification,as aGIcon- Since:
- 2.40
-
setPriority
Sets the priority of this Notification topriority.SeeGNotificationPriorityfor possible values.- Parameters:
priority- aGNotificationPriority
-
setTitle
Sets the title of this Notification totitle.- Parameters:
title- the new title for this Notification- Since:
- 2.40
-
setUrgent
Deprecated.Since 2.42, this has been deprecated in favour of g_notification_set_priority().Deprecated in favor of g_notification_set_priority().- Parameters:
urgent-trueif this Notification is urgent- Since:
- 2.40
-
builder
ANotification.Builderobject constructs aNotificationwith the specified properties. Use the variousset...()methods to set properties, and finish construction withNotification.Builder.build().- Returns:
- the builder object
-