Fix Android notification click bug and improve FCM logging

- Add FLUTTER_NOTIFICATION_CLICK intent filter to AndroidManifest.xml
- Extend initial notification message delay for terminated-state deep linking
- Add robust logging to notification listeners for easier debugging
This commit is contained in:
Patrick Britton 2026-02-04 18:01:01 -06:00
parent 48dfc76173
commit 933161cb65
2 changed files with 12 additions and 4 deletions

View file

@ -52,6 +52,11 @@
<category android:name="android.intent.category.BROWSABLE" /> <category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="sojorn" android:host="verified" /> <data android:scheme="sojorn" android:host="verified" />
</intent-filter> </intent-filter>
<!-- FCM Notification click handler -->
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity> </activity>
<!-- Don't delete the meta-data below. <!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java --> This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->

View file

@ -229,7 +229,10 @@ class NotificationService {
}); });
// Handle messages when app is opened from notification // Handle messages when app is opened from notification
FirebaseMessaging.onMessageOpenedApp.listen(_handleMessageOpen); FirebaseMessaging.onMessageOpenedApp.listen((msg) {
debugPrint('[FCM] onMessageOpenedApp triggered: ${msg.notification?.title}');
_handleMessageOpen(msg);
});
// Handle foreground messages - show in-app banner // Handle foreground messages - show in-app banner
FirebaseMessaging.onMessage.listen((message) { FirebaseMessaging.onMessage.listen((message) {
@ -241,9 +244,9 @@ class NotificationService {
// Check for initial message (app opened from terminated state) // Check for initial message (app opened from terminated state)
final initialMessage = await _messaging.getInitialMessage(); final initialMessage = await _messaging.getInitialMessage();
if (initialMessage != null) { if (initialMessage != null) {
debugPrint('[FCM] App opened from notification'); debugPrint('[FCM] App opened from TERMINATED state via notification: ${initialMessage.notification?.title}');
// Delay to allow navigation setup // Delay to allow navigation setup (extended to 1000ms for safety)
Future.delayed(const Duration(milliseconds: 500), () { Future.delayed(const Duration(milliseconds: 1000), () {
_handleMessageOpen(initialMessage); _handleMessageOpen(initialMessage);
}); });
} }