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

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

Context.startForegroundService() did not then call Service.startForeground() #1

Closed chrisdugne closed 7 months ago

chrisdugne commented 8 months ago

Hello! Thank you for providing a Godot 4 plugin v2 for android notifications.

I got my notification sent successfully, but I have an error crashing my app when the notification is received.

godot::NotificationService: onHandleIntent():: received notification id...  <--- success log
[...]

Context.startForegroundService() did not then call Service.startForeground()

(side note: also I had to rename the init() function to _ready() to initialize the Node properly)

cengiz-pz commented 8 months ago

Thanks, @chrisdugne.

(side note: also I had to rename the init() function to _ready() to initialize the Node properly)

Is this the method that you renamed?: https://github.com/cengiz-pz/godot-android-notification-scheduler-plugin/blob/f534f2608ed3c8fd150a050f6d8cb9bf2c953711/notification/addon_template/NotificationScheduler.gd#L19

Alternatively, you could call the init() method of your NotificationScheduler node in the _ready() lifecycle method of your root node.

I got my notification sent successfully, but I have an error crashing my app when the notification is received.

I will take a look at it. Do you have any more data on the crash?

wychwitch commented 7 months ago

Just wanted to post in here that I'm getting the same crash. Here's my code, and let me know if you need anything else!

extends Node2D

var label: Label;
var pressed = 0;
# Called when the node enters the scene tree for the first time.
func _ready():
    $NotificationScheduler.init()
    label = get_node("Label")
    if !$NotificationScheduler.has_post_notifications_permission():
        $NotificationScheduler.request_post_notifications_permission()
    $NotificationScheduler.create_notification_channel("my_channel_id", "My Channel Name", "My channel description")

func _on_button_pressed():
    label.text = "Pressed! " + str(pressed);
    pressed += 1;
    var my_notification_data = NotificationData.new()
    my_notification_data.set_id(9).\
            set_channel_id("my_channel_id").\
            set_title("My Notification Title").\
            set_content("My notification content").\
            set_small_icon_name("ic_notification")

    $NotificationScheduler.schedule(
            my_notification_data,
            5
        )
cengiz-pz commented 7 months ago

Hi @wychwitch, this is an issue affecting Android 12 and later versions. The issue is caused by behavior changes that were implemented by the Android team for Android version 12. Among affected functionality are foreground services, which is causing the crash mentioned on this ticket.

Link: https://developer.android.com/about/versions/12/behavior-changes-12#foreground-service-launch-restrictions

I've started looking into this yesterday. Will release a new version of the plugin when solved.

cengiz-pz commented 7 months ago

@chrisdugne, @wychwitch, please let me know if the new release (1.1) fixes your crashes. It is working on my test environment.

wychwitch commented 7 months ago

@chrisdugne, @wychwitch, please let me know if the new release (1.1) fixes your crashes. It is working on my test environment.

YES this works now!! thank you!! no crashing issues or anything. Thank you so so much ;u;

chrisdugne commented 7 months ago

I confirm 1.1 is now working properly on my side as well, thank you very much @cengiz-pz !