Normal Push Notifications appear silently or not at all when the flutter app is terminated

4,185

There are two tags that need to be intact when we are sending push from firebase api

  1. priority
  2. android_channel_id

If android 7.0 or 8.0 above device do not receive the android_channel_id than it will not show notification and so always set default notification channel in the android manifest. we can check available tags in json request we are setting via node. from here

<meta-data
    android:name="com.google.firebase.messaging.default_notification_channel_id"
    android:value="@string/default_notification_channel_id"/>

like this and make sure you create the notification channel at mobile end.

String CHANNEL_ID = "your_channel id";
String CHANNEL_DESCRIPTION = "Your description to show in settings";


NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_DESCRIPTION, NotificationManager.IMPORTANCE_HIGH);
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.createNotificationChannel(channel);

If you see the flutter app logs it will show you some error like default channel not set in manifest or no channel found in notification.

make sure you put logs in your question to resolve this or contact me to resolve the issue.

Also make sure you read Optionally handle background messages section from here fcm flutter lib there they mentioned adding fcm in android folder.

Share:
4,185
Royi Bernthal
Author by

Royi Bernthal

Updated on December 20, 2022

Comments

  • Royi Bernthal
    Royi Bernthal over 1 year

    I'm using firebase-admin on nodejs to send push notifications to users: https://firebase.google.com/docs/admin/setup

    I'm using firebase_messaging on flutter: https://pub.dev/packages/firebase_messaging

    I'm trying to send a push notification with the highest priority on both android and ios.

    firebase.messaging(firebaseApp).send({
        token,
        notification,
        android: { priority: 'high' },
        apns: { headers: { 'apns-priority': '10' }, payload: { aps: { sound: 'default' } } },
        data
    }
    

    On my development devices it works like a charm both when the app is in the background and when it's terminated.

    I'm receiving push notifications that visibly pop and make a sound 100% of the time, on both android and ios.

    The issue is on other devices -

    If the app is in the background, I can sometimes see an actual push notification visibly pop, and make a sound as it should. Sometimes not.

    If the app is terminated, a push notification is received - but it doesn't visibly pop nor make a sound, I can only see it if I scroll down the menu from the top of the screen, it's listed as a received push notification. Sometimes the notification is not receieved at all.

    I tried to change the priority of notifications from my app to high on the actual device as well, but it didn't change anything.

    My users keep complaining that they're not receiving push notifications - I'm guessing they either actually don't receieve them or simply don't see them since they're recieved silently as I described above.

    I literally have no idea what's going on and why it doesn't work as it should on devices other than my own development devices.

    Any ideas?