Skip to content

marcosdima/AndroidNotificationPlugin

Repository files navigation

AndroidNotificationPlugin

AndroidNotificationPlugin is a Godot plugin for managing and sending notifications on Android devices.


Installation

  1. Download the .zip file of this repository. (Or just clone the repository)
  2. Extract it into your project under res://addons/.
    The structure should look like this:
res://
└── addons/
    └── AndroidNotificationPlugin/
        ├── plugin.cfg
        ├── export_plugin.gd
        └── ...
  1. In Godot, go to Project → Project Settings → Plugins and activate AndroidNotificationPlugin.

Setup

  1. Add a NotificationNode to your scene.
  2. Configure notification images:
    • Load them as CompressedTexture2D.
    • Assign a resource name for each image.
    • Recommendation: set an small_icon.png for simpler implementation.
  3. Define channels:
    • At least one channel is required.
    • Important: do not repeat channel IDs.
  4. Permission: On devices running Android 13 (API 33) or higher, the POST_NOTIFICATIONS permission is required in order to display notifications. Call NotificationNode.request_post_notification() to request this permission from the user at runtime.

Usage

After setup, the plugin will be ready to use. This section describes the main functions available for sending, scheduling, and managing notifications in your Godot Android project. Examples of usage can be found in the main.gd file included in the repository.

Send a notification immediately

trigger_notification(channel: String, notification_data: Notification) -> String

Parameters:

  • channel (String): The notification channel identifier.
  • notification_data (Notification): Notification object.

Send a notification from JSON

json_notification(channel: String, json_name: String) -> String

Parameters:

  • channel (String): The notification channel identifier.
  • json_name (String): Name of the JSON file containing notification data.

Read this before use JSON


Schedule a notification after a delay

schedule(channel: String, notification_data: Notification, past_n_seconds: int = 0) -> String

Parameters:

  • channel (String): The notification channel identifier.
  • notification_data (Notification): Notification object.
  • past_n_seconds (int, optional): Delay in seconds before the notification is triggered (default is 0).

Schedule a JSON-based notification after a delay

schedule_json(channel: String, json_name: String, past_n_seconds: int = 0) -> String

Parameters:

  • channel (String): The notification channel identifier.
  • json_name (String): Name of the JSON file containing notification data.
  • past_n_seconds (int, optional): Delay in seconds before the notification is triggered (default is 0).

Read this before use JSON


Cancel a scheduled notification

cancel(notification_id: int) -> String

Parameters:

  • notification_id (int): The ID of the notification to cancel. If the notification has already been sent, it will be removed from the notification bar.

Considerations

  • NotificationNode methods return a String. This is a stringified object. If needed, you can parse it with NotificationResult.parse(res: String) -> NotificationResult Currently, the available results are: NotificationCreated, NotificationCanceled, and NotificationError. This implementation is still basic, so the methods return a String to let you handle it as you find most appropriate.
  • To save and modify JSONs use JSONHandler.save_json(name: String, data: Dictionary = {}).

Future implementations

  • Persistent scheduled notifications: ensure that scheduled notifications remain active even after the app is closed or restarted.
  • Extended customization options: provide more ways to customize notifications.

License

This project is licensed under the MIT License.

About

AndroidNotificationPlugin is a godot plugin for managing and sending notifications on Android devices.

Resources

License

Stars

Watchers

Forks

Packages

No packages published