mirror of
https://github.com/binwiederhier/ntfy.git
synced 2026-05-09 16:35:53 +02:00
[GH-ISSUE #924] [HOW] how do i get notifications when a message received when the app is terminated (flutter android) #648
Labels
No labels
ai-generated
android-app
android-app
android-app
🪲 bug
build
build
dependencies
docs
enhancement
enhancement
🔥 HOT
in-progress 🏃
ios
prio:low
prio:low
pull-request
question
🔒 security
server
server
unified-push
web-app
website
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/ntfy#648
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
@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
@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
@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/
@iamrishan commented on GitHub (Oct 21, 2023):
Thanks for the insight. I will check on the resources
@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)?
@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
@iamrishan commented on GitHub (Oct 26, 2023):
thanks