Why notifications sent from firebase console are able to bypass android background task limitation? - react-native-firebase -

Viewed 739

I try to find a way to send notifications to android devices that are limiting app activities in background, mostly Chinese brands like Huawei and Oppo.

The weird think is i'm able to receive the notification only if sent from the firebase console.

Here is how i program the notifications in the app:

const notification = new firebase.notifications.Notification()
            .setNotificationId(notificationId)
            .setTitle('some title')
            .setBody('body')
            .setData({
              screen: 'AroundMe',
            })
            .setSound('default')
            .android.setChannelId('fcm_default_channel')
            .android.setSmallIcon('ic_launcher')
            .android.setPriority(firebase.notifications.Android.Priority.Max)
            .android.setVisibility(
              firebase.notifications.Android.Visibility.Public,
            )
            .android.setAutoCancel(true)
          firebase.notifications().scheduleNotification(notification, {
            fireDate: d.getTime(),
          });

I'm aware that the app can be authorized in the phone settings so it can receive notification in background, but why the ones sent from the firebase console can be shown without that??

THANKS!

3 Answers

I think the answer of

Why notifications sent from firebase console are able to bypass android background task limitation?

is related to mechanism of push notification in android, See this:

How does push notification technology work on Android?

In this thread, described and in summary, It's because of keeping alive one Socket connection to GCM which gets notifications. Of course you can use other services of push notification like onesignal and flurry and etc but the mechanism is same.

Did you check them and you couldn't to show the notification?

In my cases this mechanism was working well with these services even on Chinese brands.

According to https://developer.android.com/topic/performance/power/power-details apps in Frequent and Rare bucket can receive only 10 and 5 FCM messages/day respectively. You can change the app stand-by mode using ADB commands.

Set app stand by bucket (set any one from active to rare):

$ adb shell am set-standby-bucket [packagename] active|working_set|frequent|rare

Get current bucket:

$ adb shell am get-standby-bucket [packagename]

(Note the value for Active is 10, Working set is 20, Frequent is 30 and Rare is 40)

After setting the app bucket to rare/frequent try sending FCM notification exceeding the limit of respective buckets.

Tip: Do NOT pull notification drawer after sending notifications - it will change app stand by state. And make sure the desired app stand by bucket state is maintained (same) throughout testing.

The current answer I have for my one question:

why the ones sent from the firebase console can be shown without that??

is that the notifications scheduled from the app are local notifications and the ones coming from Firebase Console are remote push notifications and the later ones don't need the app to be active to be displayed.

Related