Mes applications reçoivent une notification Push via Firebase. Maintenant, il a 3 situations distinctes qui peuvent se produire lorsque la notification arrive:StatusBarNotification comment obtenir des données ou renvoyer l'intention?
- L'application est au premier plan
- L'application est en arrière-plan
- L'application ne fonctionne pas
Situation 1 n'est pas un problème. La notification est reçue dans l'application ok. Les situations 2 et 3 fonctionnent correctement tant que vous appuyez sur la notification dans le tiroir. Dans les situations 2 et 3, lorsque l'icône de l'application est sélectionnée à la place de l'icône du tiroir, l'application ne reçoit aucune notification. J'ai essayé d'obtenir les notifications actives de StatusBar et cela fonctionne mais je ne peux pas récupérer les données des extras ou renvoyer la notification au service de notification push en attente. Voici le code expérimental pour obtenir les 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:
- Est-il exact que le comportement de l'application ne reçoit aucune intentions lorsqu'une notification est dans le tiroir?
- Si oui, comment gérer les situations 2 et 3 lorsque l'utilisateur appuie sur l'icône de l'application au lieu de la notification du tiroir?
Je vois ces données dans la notification de het lors de l'impression de tous les extras Valeurs clés:
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:
Vous souhaitez mettre à jour les données de votre application avec la notification? – apineda
La fonction de l'application est de vérifier une connexion à partir d'un site Web. Lorsqu'un utilisateur se connecte à un site Web spécifique avec UserId/Password, une notificationn est envoyée à l'application. Lorsque l'application s'ouvre, elle commence à rechercher un code QR qui s'affiche après la connexion sur le site Web. Les informations dans la notification doivent être égales aux informations contenues dans le code QR. Lorsque cela correspond au site Web continue à sa page d'accueil. Sinon, la connexion est refusée. –