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

Notification Scheduler Plugin allows scheduling of local notifications on the Android platform.
MIT License
21 stars 4 forks source link

"NotificationSchedulerPlugin singleton not found!" and "NotificationSchedulerPlugin singleton not initialized!" errors #8

Closed MarkoZlender closed 1 month ago

MarkoZlender commented 1 month ago

The plugin is enabled in the project and this is the code that I use on Godot 4.2.2, tried on 4.3 but the same thing happens:

extends Node

@onready var my_notification_data = NotificationData.new()

func _ready():
    if !$NotificationScheduler.has_post_notifications_permission():
        $NotificationScheduler.request_post_notifications_permission()
    else:
        print("Permission already granted")

    $NotificationScheduler.create_notification_channel(
    NotificationChannel.new()
        .set_id("my_channel_id")
        .set_name("My Channel Name")
        .set_description("My channel description")
        .set_importance(NotificationChannel.Importance.DEFAULT))

func _on_notification_scheduler_notification_opened(notification_id: int):
    print("Notification opened: ", notification_id)

func _on_notification_scheduler_permission_denied(permission_name: String):
    print("Permission denied: ", permission_name)

func _on_notification_scheduler_permission_granted(permission_name: String):
    print("Permission granted: ", permission_name)

func _on_button_pressed():
    my_notification_data.set_id(1)
    my_notification_data.set_channel_id("my_channel_id")
    my_notification_data.set_title("My Notification Title")
    my_notification_data.set_content("My notification content")
    my_notification_data.set_small_icon_name("ic_name_of_the_icon_that_you_generated")

    $NotificationScheduler.schedule(
        my_notification_data
    )
anishmishra0 commented 1 month ago

@MarkoZlender are you trying to use the plugin on non-android device?? Plugin will not work in editor, you should try using a android device or an emulator

MarkoZlender commented 1 month ago

@MarkoZlender are you trying to use the plugin on non-android device?? Plugin will not work in editor, you should try using a android device or an emulator

@anishmishra0 I am testing it on android device yes, when I press the button nothing happens.

I use Xiaomi phone and I turned off battery optimizations and enabled all notifications for the app.

anishmishra0 commented 1 month ago

@MarkoZlender I didn't noticed it first But you will have to set some delay Try this

func _on_button_pressed():
    my_notification_data.set_id(1)
    my_notification_data.set_channel_id("my_channel_id")
    my_notification_data.set_title("My Notification Title")
    my_notification_data.set_content("My notification content")
    my_notification_data.set_small_icon_name("ic_name_of_the_icon_that_you_generated")
    my_notification_data.set_delay(5)
    $NotificationScheduler.schedule(
        my_notification_data
    )
MarkoZlender commented 1 month ago

@MarkoZlender I didn't noticed it first But you will have to set some delay Try this

func _on_button_pressed():
    my_notification_data.set_id(1)
    my_notification_data.set_channel_id("my_channel_id")
    my_notification_data.set_title("My Notification Title")
    my_notification_data.set_content("My notification content")
    my_notification_data.set_small_icon_name("ic_name_of_the_icon_that_you_generated")
    my_notification_data.set_delay(5)
    $NotificationScheduler.schedule(
        my_notification_data
    )

Tried it already with the button, in the _ready function, but none of that works, same as without the delay.

MarkoZlender commented 1 month ago

I tried doing it with the demo app as well, but I don't receive any notifications.

anishmishra0 commented 1 month ago

@MarkoZlender have you setup icon correctly and name of icon match??

my_notification_data.set_small_icon_name("ic_name_of_the_icon_that_you_generated")

MarkoZlender commented 1 month ago

@MarkoZlender have you setup icon correctly and name of icon match??

my_notification_data.set_small_icon_name("ic_name_of_the_icon_that_you_generated")

Is that necessary for addon to work?

anishmishra0 commented 1 month ago

Is that necessary for addon to work?

yes

anishmishra0 commented 1 month ago

@MarkoZlender Is your problem solved ??

MarkoZlender commented 1 month ago

It's working now yes. Thank you for pointing out the icon part. Although please add short instructions to the README for generating icons.

For anyone in the future having problems with this:

  1. Create empty android project in Android Studio
  2. Right click on res folder -> New -> Image asset -> Select Icon type: Notification Icons -> Input the name for icons -> Next -> Finish
  3. Right click on res/drawable folder and open in file explorer
  4. Copy these folders to your godot project inside android/build/res folder and make sure they contain icons with your specified name:
    • drawable-anydpi
    • drawable-xxhdpi
    • drawable-xhdpi
    • drawable-hdpi
    • drawable-mdpi
  5. Make sure you use the name you specified for your icons when initializing notifications: my_notification_data.set_small_icon_name("<your_notification_icon_name_here>")
  6. Export your apk or Remote Debug
anishmishra0 commented 1 month ago

It's working now yes

That's Great, @MarkoZlender close this issue as completed.