I have a flutter app that listens to firebase notifications in the foreground, using FirebaseMessaging.onMessage.listen.
I could reproduce a scenario where the listener does not get invoked even though the device is receiving the token (I can see it in adb logcat, more on that below).
Scenario 1
- Fresh install the app from android studio (app was not installed before on the device)
- open the app (app is now in foreground, and ofcourse firebase is initialized in code)
- send a firebase fcm notification from the server
- the notification is received normally by the app and
onMessageis invoked. - relative logcat part:
02-08 20:54:59.868 1266 1266 D [email protected]: WifiRequest::create vendor command to iface 31, vendor_id=0x1a11, subcmd=0x1200, res=0
02-08 20:54:59.868 1266 1266 I [email protected]: WifiCommand::requestResponse err=-14
02-08 20:54:59.868 1266 1266 I WifiHAL : wifi_get_link_stats: result=-1
02-08 20:54:59.869 1103 1205 E WifiVendorHal: getWifiLinkLayerStats_1_5_Internal(l.1191) failed {.code = ERROR_UNKNOWN, .description = unknown}
02-08 20:54:59.974 1103 2839 D AlarmManagerService: inside native alarm timerfd set Alarm Type = 2
02-08 20:54:59.975 1103 2839 D AlarmManagerService: inside native alarm timerfd set Alarm Type = 3
02-08 20:54:59.975 14787 18725 I AlarmManager: setExactAndAllowWhileIdle [name: GCM_HB_ALARM type: 2 triggerAtMillis: 258634626]
02-08 20:54:59.976 1103 2839 D AlarmManagerService: inside native alarm timerfd set Alarm Type = 2
02-08 20:54:59.977 1103 2839 D AlarmManagerService: inside native alarm timerfd set Alarm Type = 3
02-08 20:54:59.985 14787 18724 W ChimeraUtils: Module com.google.android.gms.gcm missing resource null(0)
02-08 20:54:59.990 14787 18724 I AlarmManager: setExactAndAllowWhileIdle [name: FcmRetry type: 2 triggerAtMillis: 258284640]
02-08 20:54:59.991 1103 2527 D AlarmManagerService: inside native alarm timerfd set Alarm Type = 2
02-08 20:54:59.992 1103 2527 D AlarmManagerService: inside native alarm timerfd set Alarm Type = 3
02-08 20:54:59.998 18477 18477 D FLTFireMsgReceiver: broadcast received for message
02-08 20:55:00.000 1103 1186 D AlarmManagerService: inside native alarm timerfd set Alarm Type = 2
02-08 20:55:00.001 1103 1186 D AlarmManagerService: inside native alarm timerfd set Alarm Type = 2
02-08 20:55:00.007 18477 18530 I flutter : newRemoteMessage.data: {data: data, requestId: 3197, type: disclaimer}
02-08 20:55:00.034 1103 2527 D AlarmManagerService: inside native alarm timerfd set Alarm Type = 2
02-08 20:55:00.034 14787 18725 I AlarmManager: setExactAndAllowWhileIdle [name: GCM_HB_ALARM type: 2 triggerAtMillis: 258634686]
02-08 20:55:00.035 1103 1425 D AlarmManagerService: inside native alarm timerfd set Alarm Type = 2
notice the lines
02-08 20:54:59.998 18477 18477 D FLTFireMsgReceiver: broadcast received for message
and
02-08 20:54:59.985 14787 18724 W ChimeraUtils: Module com.google.android.gms.gcm missing resource null(0)
Scenario 2
- starting from scenario 1's last step, stop the app from android studio (recall it was launched in debug mode in android studio on a real device)
- rerun the app (from android studio or by simply tapping the app's icon using my finger)
- send a notification
- notification not received by the app (
onMessageis not invoked), but as you can see from logs below it was received by the device but for some reason not propagated to the app - relative logcat part:
02-08 20:00:18.752 1266 1266 I WifiHAL : wifi_get_link_stats: result=-1
02-08 20:00:18.753 1103 1205 E WifiVendorHal: getWifiLinkLayerStats_1_5_Internal(l.1191) failed {.code = ERROR_UNKNOWN, .description = unknown}
02-08 20:00:19.019 593 593 I BufferQueueProducer: [SurfaceView[com.myapp/com.example.myapp.MainActivity](BLAST)#0](this:0xb4000075ade3a438,id:-1,api:0,p:-1,c:593) queueBuffer: fps=15.81 dur=1011.73 max=260.93 min=16.28
02-08 20:00:19.021 572 912 I hwcomposer: [HWCDisplay] [Display_0 (type:1)] fps:15.811406,dur:1011.93,max:260.75,min:16.30
02-08 20:00:19.139 1103 1584 D AlarmManagerService: inside native alarm timerfd set Alarm Type = 2
02-08 20:00:19.139 1103 1584 D AlarmManagerService: inside native alarm timerfd set Alarm Type = 3
02-08 20:00:19.140 14787 16544 I AlarmManager: setExactAndAllowWhileIdle [name: GCM_HB_ALARM type: 2 triggerAtMillis: 255353791]
02-08 20:00:19.142 1103 1584 D AlarmManagerService: inside native alarm timerfd set Alarm Type = 2
02-08 20:00:19.142 1103 1584 D AlarmManagerService: inside native alarm timerfd set Alarm Type = 3
02-08 20:00:19.150 14787 15491 W ChimeraUtils: Module com.google.android.gms.gcm missing resource null(0)
02-08 20:00:19.158 14787 15491 I AlarmManager: setExactAndAllowWhileIdle [name: FcmRetry type: 2 triggerAtMillis: 255003806]
02-08 20:00:19.163 1103 5302 D AlarmManagerService: inside native alarm timerfd set Alarm Type = 2
02-08 20:00:19.163 1103 5302 D AlarmManagerService: inside native alarm timerfd set Alarm Type = 3
02-08 20:00:19.171 1103 1131 D BroadcastQueue: processNextBroadcastLocked, suppress to start process of staticReceiver for package:com.myapp
02-08 20:00:19.172 1103 1131 D BroadcastQueue: processNextBroadcastLocked, suppress to start process of staticReceiver for package:com.myapp
02-08 20:00:19.173 14787 14787 W GCM : broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000000 pkg=com.myapp (has extras) }
02-08 20:00:19.188 1103 5302 D AlarmManagerService: inside native alarm timerfd set Alarm Type = 2
02-08 20:00:19.188 1103 5302 D AlarmManagerService: inside native alarm timerfd set Alarm Type = 3
02-08 20:00:19.189 14787 16544 I AlarmManager: setExactAndAllowWhileIdle [name: GCM_HB_ALARM type: 2 triggerAtMillis: 255353840]
02-08 20:00:19.190 1103 5302 D AlarmManagerService: inside native alarm timerfd set Alarm Type = 2
02-08 20:00:19.190 1103 5302 D AlarmManagerService: inside native alarm timerfd set Alarm Type = 3
focus at the line
02-08 20:00:19.173 14787 14787 W GCM : broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000000 pkg=com.myapp (has extras) }
Question is why is this happening and how to solve it? This is even happening for release versions of the app (the release versions are distributed through an apk and not playstore, and also the app in release version is runnnig in kiosk mode using airdroid mdm which prevents the app from closing, so the app is in foreground the whole time)