0

The FCMService.java handles all the background notification tasks perfectly if the app is running in foreground. When i close the application from the app drawer the aforementioned service stops handling the delivered fcm message, instead throws following log

W/GCM: broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000000 pkg=com.technobees.nalamdot (has extras) }

I've tested in following devices with user enabling isIgnoringBatteryOptimizations using the permission ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS.

  1. Oneplus 3t
  2. Xiaomi Redmi 4, Note 4, Note 5 pro (MIUI optimization disabled)

Message sending from node server

var message = { 'data': notification, 'token': token, "android": { "ttl": 0, "priority": "HIGH" }, "webpush": { "headers": { "TTL": "3000" } } };

in FCMService.java

@Override public void onMessageReceived(RemoteMessage remoteMessage) { Map<String, String> data = remoteMessage.getData(); //passing the data to the NotificationUtils -> which takes action based on "event" }

Arun
  • 154
  • 1
  • 12

2 Answers2

0

Inserting these lines in the android manifest worked for me,

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-permission android:name="android.permission.WAKE_LOCK" />

yogesh
  • 11
  • 5
-1

if you want to receive notification while app is in closed stated then try adding these permission in your manifest file:

 <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
 <uses-permission android:name="android.permission.WAKE_LOCK" />
nik
  • 345
  • 1
  • 9
  • 1
    not working still – Arun Jul 19 '18 at 12:30
  • 1
    can you share the code – nik Jul 19 '18 at 13:13
  • notification payload can be send using data tag or notification tag.using data tag it will trigger the FirebaseMessagingService onMessageReceived method. it will not work on some devices, when an app is in the background. Refer this:--- https://stackoverflow.com/questions/44847835/android-fcm-not-receiving-notifications-when-app-is-removed-from-background/45810771#45810771 – nik Jul 20 '18 at 08:52
  • That log is mentioned above in question. – Arun Jul 20 '18 at 10:06
  • have checked the above link – nik Jul 20 '18 at 11:32
  • The problem i found is that FCM messages is not handled in debug mode by these Custom Android Versions. But in production, its fine – Arun Sep 24 '18 at 10:11