gdx-notifications
Cross-platform notifications for libgdx.
See here for an example implementation.
Setup
This library needs libgdx starting from version 1.5.5.
Add the pretty bold parts into your build.gradle file:
allprojects { ext { gdxNotificationsVersion = '1.0.0' } } ... repositories { jcenter() Only necessary if you plan to use JCommunique } ... project(":desktop") { ... dependencies { compile project(":core") ... compile "games.spooky.gdx:gdx-notifications-desktop-jcommunique:$gdxNotificationsVersion" for Swing notifications OR compile "games.spooky.gdx:gdx-notifications-desktop-os:$gdxNotificationsVersion" for native notifications } } project(":android") { ... dependencies { compile project(":core") ... compile "games.spooky.gdx:gdx-notifications-android:$gdxNotificationsVersion" } } project(":html") { ... dependencies { compile project(":core") ... compile "games.spooky.gdx:gdx-notifications-html-gwt:$gdxNotificationsVersion" compile "games.spooky.gdx:gdx-notifications:$gdxNotificationsVersion:sources" compile "games.spooky.gdx:gdx-notifications-html-gwt:$gdxNotificationsVersion:sources" for gwt notifications OR compile "games.spooky.gdx:gdx-notifications-html-browser:$gdxNotificationsVersion" compile "games.spooky.gdx:gdx-notifications:$gdxNotificationsVersion:sources" compile "games.spooky.gdx:gdx-notifications-html-browser:$gdxNotificationsVersion:sources" for browser notifications } } project(":core") { ... dependencies { ... compile "games.spooky.gdx:gdx-notifications:$gdxNotificationsVersion" } }
Add
<inherits name="games.spooky.gdx.notifications.gdx_notifications_gwt"/>
after
<inherits name='com.badlogic.gdx.backends.gdx_backends_gwt'/>
in your GdxDefinition.gwt.xml
.
Usage
Initialization
We're talking platform-specific stuff here, so you'll need to initialize the magic in your specific initializers. Simply follow the indications from libgdx's wiki.
Classes you'll have for this:
DesktopNotificationHandler
(desktop, whether it's from JCommunique or java-to-OS-notify)AndroidNotificationHandler
(warning, notifications are not supported for android versions below 14)HtmlNotificationHandler
And the base interface with two methods:
NotificationHandler
Notify
NotificationHandler handler = <your_platform-specific_handler_here>;
handler.showNotification(new NotificationParameters(12, "Notification title for the people", "Text Lorem ipsum"));
Remove notification
NotificationHandler handler = <your_platform-specific_handler_here>;
// You could (should!) very well get the parameters object from above
// But it will go nice too if you create a new object
// Only the id matters actually
handler.hideNotification(new NotificationParameters(12, "", ""));
Platform support
- Desktop (swing via JCommunique, native via java-to-OS-notify)
- Android
- iOS
- HTML (gwt via NotificationMole, browser via Notification Web-API)