[GH-ISSUE #924] [HOW] how do i get notifications when a message received when the app is terminated (flutter android) #648

Closed
opened 2026-05-07 00:26:15 +02:00 by BreizhHardware · 7 comments

Originally created by @iamrishan on GitHub (Oct 20, 2023).
Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/924

I'm using the ntfy API to receive notifications on my own app in Flutter/Android.
I completed the part to receive notifications when the app is in the foreground or background using a package called flutter_local_notifications.
but when the app is closed/terminated no notification is coming. how do I implement this with ntfy API

Originally created by @iamrishan on GitHub (Oct 20, 2023). Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/924 I'm using the ntfy API to receive notifications on my own app in Flutter/Android. I completed the part to receive notifications when the app is in the foreground or background using a package called flutter_local_notifications. but when the app is closed/terminated no notification is coming. how do I implement this with ntfy API
Author
Owner

@wunter8 commented on GitHub (Oct 20, 2023):

When you close the app, it's closing the connection to the ntfy server. You'll probably want to look into and implement UnifiedPush. Or you'll need to implement something else to keep a connection to the server open in the background

<!-- gh-comment-id:1772773375 --> @wunter8 commented on GitHub (Oct 20, 2023): When you close the app, it's closing the connection to the ntfy server. You'll probably want to look into and implement UnifiedPush. Or you'll need to implement something else to keep a connection to the server open in the background
Author
Owner

@iamrishan commented on GitHub (Oct 20, 2023):

Yeah! I know Firebase has a background function to workwith background notification using FCM.
But how does the ntfy.sh android app can do this. if they can do it there will be a way,,,
if the app is closed still the notification is coming in this app when a new message is send to that topic

<!-- gh-comment-id:1773085712 --> @iamrishan commented on GitHub (Oct 20, 2023): Yeah! I know Firebase has a background function to workwith background notification using FCM. But how does the [ntfy.sh android app](https://play.google.com/store/apps/details?id=io.heckel.ntfy) can do this. if they can do it there will be a way,,, if the app is closed still the notification is coming in this app when a new message is send to that topic
Author
Owner

@wunter8 commented on GitHub (Oct 20, 2023):

The ntfy Android app typically keeps a persistent connection open to the ntfy server using a background process/service. If that persistent connection fails (and the app was installed from the Play Store and not from F-Droid), ntfy will fallback to receiving notifications via FCM, which does work in the background, like you said.

All of the Android code is open-source, so you can look at it directly to see how things work. https://github.com/binwiederhier/ntfy-android It is in Kotlin, though, not Flutter/Dart.

UnifiedPush is cool because it lets your app receive notifications through ntfy's persistent connection. So you don't need to worry about setting up any sort of persistent network connection with graceful FCM back up. As long as ntfy is installed on the same device as your app, your app can benefit from ntfy's persistent connection. In your app, I believe all you need to do is set up a BroadcastReceiver that listens for UnifiedPush messages.

This describes UnifiedPush more and includes a Flutter example: https://unifiedpush.org/developers/flutter/

<!-- gh-comment-id:1773100775 --> @wunter8 commented on GitHub (Oct 20, 2023): The ntfy Android app typically keeps a persistent connection open to the ntfy server using a background process/service. If that persistent connection fails (and the app was installed from the Play Store and not from F-Droid), ntfy will fallback to receiving notifications via FCM, which does work in the background, like you said. All of the Android code is open-source, so you can look at it directly to see how things work. https://github.com/binwiederhier/ntfy-android It is in Kotlin, though, not Flutter/Dart. UnifiedPush is cool because it lets your app receive notifications through ntfy's persistent connection. So you don't need to worry about setting up any sort of persistent network connection with graceful FCM back up. As long as ntfy is installed on the same device as your app, your app can benefit from ntfy's persistent connection. In your app, I believe all you need to do is set up a BroadcastReceiver that listens for UnifiedPush messages. This describes UnifiedPush more and includes a Flutter example: https://unifiedpush.org/developers/flutter/
Author
Owner

@iamrishan commented on GitHub (Oct 21, 2023):

Thanks for the insight. I will check on the resources

<!-- gh-comment-id:1773666768 --> @iamrishan commented on GitHub (Oct 21, 2023): Thanks for the insight. I will check on the resources
Author
Owner

@iamrishan commented on GitHub (Oct 24, 2023):

@wunter8 hey I tried to implement it with FCM. I stuck where I need to subscribe to a topic in FCM to receive notifications in the background .
I tried the same topic as my nfty topic but I think that's not it.
do you tend to know what will be the server topic for my specific nfty topic (eg. mytopic in ntfy.sh)?

image

<!-- gh-comment-id:1776940526 --> @iamrishan commented on GitHub (Oct 24, 2023): @wunter8 hey I tried to implement it with FCM. I stuck where I need to subscribe to a topic in FCM to receive notifications in the background . I tried the same topic as my nfty topic but I think that's not it. do you tend to know what will be the server topic for my specific nfty topic (eg. mytopic in ntfy.sh)? ![image](https://github.com/binwiederhier/ntfy/assets/52799367/6fdb8e43-4148-4744-ad38-bb2c0868c6b7)
Author
Owner

@wunter8 commented on GitHub (Oct 24, 2023):

I don't know for sure. I haven't used FCM very much. But I'm pretty sure you can use whatever you want. Since you're building the app, you get to decide how notifications and subscriptions work. I believe ntfy is set up to subscribe to a FCM topic that's the same as the ntfy topic, though

<!-- gh-comment-id:1777140036 --> @wunter8 commented on GitHub (Oct 24, 2023): I don't know for sure. I haven't used FCM very much. But I'm pretty sure you can use whatever you want. Since you're building the app, you get to decide how notifications and subscriptions work. I believe ntfy is set up to subscribe to a FCM topic that's the same as the ntfy topic, though
Author
Owner

@iamrishan commented on GitHub (Oct 26, 2023):

thanks

<!-- gh-comment-id:1780398556 --> @iamrishan commented on GitHub (Oct 26, 2023): thanks
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ntfy#648
No description provided.