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(java.lang.String, org.gnome.gio.ApplicationFlags...)
.
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)
.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Notification.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
ConstructorDescriptionNotification
(MemorySegment address) Create a Notification proxy instance for the provided memory address.Notification
(String title) Creates a newGNotification
withtitle
as its title. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a button to this Notification that activates the action indetailedAction
when clicked.void
addButtonWithTarget
(String label, String action, @Nullable Variant target) Adds a button to this Notification that activatesaction
when clicked.protected Notification
asParent()
Returns this instance as if it were its parent type.static Notification.Builder
<? extends Notification.Builder> builder()
ANotification.Builder
object constructs aNotification
with the specified properties.static Type
getType()
Get the GType of the Notification classvoid
Sets the body of this Notification tobody
.void
setCategory
(@Nullable String category) Sets the type of this Notification tocategory
.void
setDefaultAction
(String detailedAction) Sets the default action of this Notification todetailedAction
.void
setDefaultActionAndTarget
(String action, @Nullable Variant target) Sets the default action of this Notification toaction
.void
Sets the icon of this Notification toicon
.void
setPriority
(NotificationPriority priority) Sets the priority of this Notification topriority
.void
Sets the title of this Notification totitle
.void
setUrgent
(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, 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, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.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 newGNotification
withtitle
as its title.After populating
notification
with 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
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, 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 indetailedAction
when clicked. That action must be an application-wide action (starting with "app."). IfdetailedAction
contains 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
-
addButtonWithTarget
Adds a button to this Notification that activatesaction
when clicked.action
must be an application-wide action (it must start with "app.").If
target
is non-null
,action
will be activated withtarget
as its parameter.- Parameters:
label
- label of the buttonaction
- an action nametarget
- aGVariant
to use asaction
's parameter, ornull
-
setBody
Sets the body of this Notification tobody
.- Parameters:
body
- the new body for this Notification, ornull
-
setCategory
Sets the type of this Notification tocategory
. Categories have a main type likeemail
,im
ordevice
and can have a detail separated by a.
, e.g.im.received
oremail.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 for this Notification, ornull
for no category
-
setDefaultAction
Sets the default action of this Notification todetailedAction
. This action is activated when the notification is clicked on.The action in
detailedAction
must be an application-wide action (it must start with "app."). IfdetailedAction
contains 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
-
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
target
is non-null
,action
will be activated withtarget
as its parameter. Iftarget
is 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
- aGVariant
to use asaction
's parameter, ornull
-
setIcon
Sets the icon of this Notification toicon
.- Parameters:
icon
- the icon to be shown in this Notification, as aGIcon
-
setPriority
Sets the priority of this Notification topriority
. SeeGNotificationPriority
for possible values.- Parameters:
priority
- aGNotificationPriority
-
setTitle
Sets the title of this Notification totitle
.- Parameters:
title
- the new title for this Notification
-
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
-true
if this Notification is urgent
-
builder
ANotification.Builder
object constructs aNotification
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withNotification.Builder.build()
.
-