My Apps receives Push Notification via Firebase. Now there a 3 distinct situations that can happen when the notification arrives:
- The app is in the foreground
- The app is in the background
- The app is not running
Situation 1 is no problem. The notification is received in the app ok. Situation 2 and 3 work fine as long as you tap the notification in the drawer. In Situation 2 and 3 when the app icon is tapped instead of the drawer icon the app does not receive any notification at all. I've tried to get the active notifications from the StatusBar and that works but I can not either retrieve the data from the Extras or resend the notification to the waiting push notification service. Here's the experimental code to get the Notifications.
NotificationManager notificationManager = (NotificationManager)Application.Context.GetSystemService(Context.NotificationService);
var notifications = notificationManager.GetActiveNotifications()
.Where(notif => notif.PackageName == Application.Context.PackageName);
foreach (var notification in notifications)
{
Log.Info(TAG, "OnActivityResumed: Notification in active in Status Bar: {0}", notification.Notification.ToString());
var data = notification.Notification.Extras.GetString("data");
Log.Debug("Notifier", "Data received: {0}", data);
//if (data != null)
//{
// Settings.Notification = JsonConvert.DeserializeObject<LoginNotificationParameter>(data);
//}
}
// Canceling all notifications
notificationManager.CancelAll();
Questions:
- Is it correct behavior that the app does not receive any intents when a notification is in the drawer?
- If so how to I handle situations 2 and 3 when the user tapps the app icon instead of the drawer notification?
I see this data in het Notification when printing all the Extras Key Values:
06-28 16:34:13.174 20792 20792 I Notifier: OnActivityResumed: Notification is active in Status Bar: Notification(pri=0 contentView=null vibrate=null sound=content://settings/system/notification_sound defaults=0x0 flags=0x10 color=0x00000000 vis=PRIVATE semFlags=0x0 semPriority=0)
06-28 16:34:13.191 20792 20792 I Notifier: KeyIn: Extras Key: android.title Data: Login
06-28 16:34:13.191 20792 20792 I Notifier: KeyIn: Extras Key: android.subText Data:
06-28 16:34:13.191 20792 20792 I Notifier: KeyIn: Extras Key: android.template Data: android.app.Notification$BigTextStyle
06-28 16:34:13.192 20792 20792 I Notifier: KeyIn: Extras Key: android.showChronometer Data: false
06-28 16:34:13.192 20792 20792 I Notifier: KeyIn: Extras Key: android.text Data: Er is een inlogverzoek voor u ontvangen.
06-28 16:34:13.194 20792 20792 I Notifier: KeyIn: Extras Key: android.progress Data: 0
06-28 16:34:13.194 20792 20792 I Notifier: KeyIn: Extras Key: android.progressMax Data: 0
06-28 16:34:13.195 20792 20792 I Notifier: KeyIn: Extras Key: android.appInfo Data: ApplicationInfo{a27f281 nl.natuurnetwerk.notifier}
06-28 16:34:13.195 20792 20792 I Notifier: KeyIn: Extras Key: android.showWhen Data: true
06-28 16:34:13.195 20792 20792 I Notifier: KeyIn: Extras Key: android.largeIcon Data:
06-28 16:34:13.195 20792 20792 I Notifier: KeyIn: Extras Key: android.bigText Data: Er is een inlogverzoek voor u ontvangen.
06-28 16:34:13.195 20792 20792 I Notifier: KeyIn: Extras Key: android.infoText Data:
06-28 16:34:13.195 20792 20792 I Notifier: KeyIn: Extras Key: android.originatingUserId Data: 0
06-28 16:34:13.196 20792 20792 I Notifier: KeyIn: Extras Key: android.progressIndeterminate Data: false
06-28 16:34:13.196 20792 20792 I Notifier: KeyIn: Extras Key: android.remoteInputHistory Data: