Skip to content

cengiz-pz/godot-android-notification-scheduler-plugin

Repository files navigation


Notification Scheduler Plugin

Notification Scheduler Plugin allows scheduling of local notifications on the Android platform.

For iOS version, visit https://github.com/cengiz-pz/godot-ios-notification-scheduler-plugin .

Prerequisites

Follow instructions on the following page to create a custom Android gradle build

Prior to using this plugin, a notification icon should be generated. For instructions please visit the following link:

Installation

There are 2 ways to install the Notification Scheduler plugin into your project:

  • Through the Godot Editor's AssetLib
  • Manually by downloading archives from Github

Installing via AssetLib

Steps:

  • search for and select the Android Notification Scheduler plugin in Godot Editor
  • click Download button
  • on the installation dialog...
    • keep Change Install Folder setting pointing to your project's root directory
    • keep Ignore asset root checkbox checked
    • click Install button
  • enable the plugin via the Plugins tab of Project->Project Settings... menu, in the Godot Editor

Installing manually

Steps:

  • download release archive from Github
  • unzip the release archive
  • copy to your Godot project's root directory
  • enable the plugin via the Plugins tab of Project->Project Settings... menu, in the Godot Editor

Notification icon

Copy your notification icon to your project's android/build/res directory.

Alternatively, you could use Android Studio's Image Asset Studio to generate your icon set.

Note: the notification icon resource should be of type drawable

Usage

Add a NotificationScheduler node to your scene and follow the following steps:

  • Register listeners for the following signals emitted from the NotificationScheduler node
    • notification_opened - when user taps notification item
    • permission_granted
    • permission_denied
  • At startup, using the NotificationScheduler node to check that the application has permissions to post notifications:
	$NotificationScheduler.has_post_notifications_permission()
  • If the application doesn't have permissions to post notifications, then request permission using the NotificationScheduler node:
	$NotificationScheduler.request_post_notifications_permission()
  • permission_granted signal will be emitted when the application receives the permissions

  • Create a notification channel using the NotificationScheduler node:

	$NotificationScheduler.create_notification_channel("my_channel_id", "My Channel Name", "My channel description")
  • Build NotificationData object:
	var my_notification_data = NotificationData.new()
	my_notification_data.set_id(__notification_id).\
			set_channel_id("my_channel_id").\
			set_title("My Notification Title").\
			set_content("My notification content").\
			set_small_icon_name("ic_name_of_the_icon_that_you_generated").\
			set_delay(my_delay_in_seconds)
  • Schedule notification using the NotificationScheduler node:
	$NotificationScheduler.schedule(
			my_notification_data
		)
  • NotificationData's set_interval(interval_in_seconds) method can be used for scheduling repeating notifications.
  • NotificationData's set_deeplink(data) method can be used for delivering URI data along with the notification.

Other Available Methods

  • cancel(notification_id)
  • get_notification_id() - alternative way to get the ID of the last opened notification.

Demo

  • Restore the following notification icons after Android Build Template is installed for the demo app.
    • demo/android/build/res/drawable-anydpi-v24/ic_demo_notification.xml
    • demo/android/build/res/drawable-hdpi/ic_demo_notification.png
    • demo/android/build/res/drawable-mdpi/ic_demo_notification.png
    • demo/android/build/res/drawable-xhdpi/ic_demo_notification.png
    • demo/android/build/res/drawable-xxhdpi/ic_demo_notification.png

Troubleshooting

adb logcat is one of the best tools for troubleshooting unexpected behavior

  • use $> adb logcat | grep 'godot' on Linux
    • adb logcat *:W to see warnings and errors
    • adb logcat *:E to see only errors
    • adb logcat | grep 'godot|somethingElse' to filter using more than one string at the same time
  • use #> adb.exe logcat | select-string "godot" on powershell (Windows)

Also check out: https://docs.godotengine.org/en/stable/tutorials/platform/android/android_plugin.html#troubleshooting



Credits

Developed by Cengiz

Original repository: Godot Android Notification Scheduler Plugin

About

Notification Scheduler Plugin allows scheduling of local notifications on the Android platform.

Resources

License

Stars

Watchers

Forks

Packages

No packages published