Notification not showing when the app is closed
Supporting Fire-base push notification for all device is like a maze.
There are 3 scenario for push notification
- Foreground (fire
FirebaseMessagingService
'sonMessageReceived
method) - Background (can't fire
FirebaseMessagingService
but firebase service push their message into device's Notification Tray) - App kill (can't fire
FirebaseMessagingService
firebase service push push their message into device's Notification Tray)
NOTE: Some chinese device like Xiaomi, Asus, Huawei etc. are force stop your app when you swipe out from your background stack, so that the service is kill. For that reason firebase service is not run and can't push their notification into Notification tray.
In Xiaomi - security-->permissions-->autostart then check mark your app. Enable this means app's any service always run in background. Then you get all kinds of notification from your app every time.
If you want to learn more about that, Check that
and if you want to go particular device's security page from your app then check this.
Push notification not displayed when app is closed in android
Add BootBroadcastReceiver in Manifest file
<receiver
android:name=".OnBootBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
Create Following Java file. call the FirebaseMessagingReceiveService inside it.
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class OnBootBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent("com.demo.FirebaseMessagingReceiveService");
i.setClass(context, FirebaseMessagingReceiveService.class);
context.startService(i);
}
}
Android Repeated Notifications not working When App is Closed
You shouldn't use any part of application to do that. Services, JobScheduler, or Work Manager sooner or later will be killed by the system to prevent battery drain.
In my opinion the best way to send repeated notifications is to use firebase cloud messaging triggered with external cron job (e.g. php on firebase functions).
Also make sure to deliver the notification to the system tray not to the application. To do that use FCM DataMessages. Data messages are delivered to system tray and are always display - even if service is not running.
PWA stop receiving push notification on android app closed
Found the problem. The problem here was the Event Listener on the service-worker was getting the clients to verify if the application was already open, but I was assuming there would always be a client on the list, even when the app is closed. The correct way would be something like:
self.addEventListener('push', (e) => {
let notificationData
e.waitUntil(
clients.matchAll({ type: 'window' }).then(function(clientList) {
const client = clientList.find(c => c.visibilityState === 'visible') // <- This validation
if (e.data && !client) {
const envelope = e.data.json()
// Process the notification
// ...
e.waitUntil(self.registration.showNotification(data.subject, options))
}
})
)
})
Flutter / Firebase push notifications not fired when app is closed
As per your data send with fcm is sending only data object not notification object as per the fcm to wakeup it self you need to send notification object along with data object.
https://firebase.google.com/docs/cloud-messaging/concept-options
Related Topics
Android Force Gpu Rendering How to Enable and Disable
Android Sdk Is Mssing ,Out of Date or Corrupted
Android How to Get Current Positon on Recyclerview That User Scrolled to Item
Setting Webview to View Desktop Site and Not Mobile Site
How to Edit Files Inside the Android Adb Shell
Showing Thumbnail for Link in Whatsapp || Og:Image Meta-Tag Doesn't Work
Concatenate Multiple Strings in Xml
How to Set the Preview Image in Videoview Before Playing
How to Display HTML in Textview
Why Is the Android Emulator So Slow? How to Speed Up the Android Emulator
Adb Error (Error: Protocol Fault (Couldn't Read Status): Invalid Argument)
Disable Ssl as a Protocol in Httpsurlconnection
Recyclerview Is Cutting Off the Last Item
Android Adb Devices Does Not Detect My Phone
How to Disable Edittext in Android
Detect or Prevent If User Uses Fake Location
How to Set Space Between Listview Items in Android
React Native | Failed to Install the App. Please Accept All Necessary Sdk Licenses Using Sdk Manager