Android Push Notifications Not Being Received When App Closed

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

  1. Foreground (fire FirebaseMessagingService's onMessageReceived method)
  2. Background (can't fire FirebaseMessagingService but firebase service push their message into device's Notification Tray)
  3. 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
Sample Image



Related Topics



Leave a reply



Submit