DelphiWorlds / Kastri

Cross-platform library for Delphi
MIT License
489 stars 119 forks source link

Support FLAG_INSISTENT in the Notifications feature (Android only) #235

Closed MyBuzzTechnologies closed 1 month ago

MyBuzzTechnologies commented 3 months ago

I use the notification feature of Kastri for an alarm-type function in my app.

To make the notifications more annoying (deliberately), I'm using a customised version of the DW.Notifications.Android.pas which adds the Insistent flag to the built Notification in GetNativeNotification(). The Insistent flag makes the notifications keep repeating their alert sound and vibration until the user taps it.

It would be great if this could be officially added to the feature. I appreciate it will only have an impact on Android (iOS has no equivalent), but would be very helpful and offer something that the EMB implementation doesn't.

I'd like it to do this for immediate and scheduled notifications on Android, as that's what my customised version of your unit does today.

Thanks!

DelphiWorlds commented 3 months ago

Not sure how it would have been working for scheduled notifications before.. but it should work for immediate notifications. The trouble is that with scheduled notifications, the notification needs to be "rebuilt" when the alarm fires, so any flags it requires need to be saved in the pending intent so they can be "restored" in the presented notification. This is performed in Java code which is in dw-kastri-base.x.x.x.jar.

I've now pushed changes that should support this. Set the IsInsistent property of TNotification to True. It should also work for push notifications using the FCM support in Kastri if isInsistent is included in the data member of the payload. It doesn't matter what the value is (a string value), as long as it is present.

MyBuzzTechnologies commented 3 months ago

I'm not sure how it was working before tbh after seeing your changes but it has been for years! Weird.

Either way, thanks for officially including this, it's one less overridden source I need to manage!