2

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!

B. Mohammad
  • 2,152
  • 1
  • 13
  • 28

3 Answers3

1

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.

AMK
  • 662
  • 6
  • 16
  • No i did not test on OneSignal and Flurry. The thing is a send notifications from firebase using two ways: 1-from the console; it reach the phone even when in background 2- from the app it does not reach the phone if in background. – B. Mohammad Aug 21 '20 at 08:28
  • Do you mean your sent notifications from server side(Node.js, Laravel or etc) never catch in client? If it's so, It seems you have problem in back-end and is not related to background or foreground. Did you check your keys when you want to send notifications in back-end? – AMK Aug 21 '20 at 08:38
  • no i mean in the client app (react-native), i schedule notification using `react-native-firebase`, but in Chinese phone those are never received if app is in background. For other phone it works no problem. – B. Mohammad Aug 21 '20 at 09:00
  • 1
    Aha! I develop native android and I don't know about react-native but yes on Chinese brands it's been strongly limited to have background services alive unless user let the app via auto-start, It seems react-native doesn't implement proper way for getting notifications, by the way when I'm using just FCMService in my app like documentations, It works well but when I was using scheduler or another services on background they were killed when app closed and no notification received. – AMK Aug 21 '20 at 09:25
0

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.

Try this
  • 511
  • 3
  • 8
  • Thanks for your answer, but is does not answer why notification sent from the firebase console reach the phone (testing on a Huawei) while does programmed by the app does not. – B. Mohammad Aug 14 '20 at 12:10
  • When you say programmed by app you meant triggered by code inside app (may be by some service or job?)? – Try this Aug 14 '20 at 12:27
0

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.

B. Mohammad
  • 2,152
  • 1
  • 13
  • 28