Flutter应用点击C#推送通知无法启动问题排查及正确Payload配置咨询
Hey there, let's break down why your push notification isn't launching your Flutter app when clicked, even though you've set up the FLUTTER_NOTIFICATION_CLICK intent filter. Here are the likely issues and fixes:
Possible Root Causes
1. Invalid badge Field Value
Your current payload sets badge to a link, but Android expects a numeric value (e.g., 1) for the app icon badge. A non-numeric value here can cause notification parsing errors, which might prevent the click action from triggering correctly.
2. Missing Android-Specific Notification Configuration
Firebase Cloud Messaging (FCM) often requires explicit Android-specific settings to ensure the notification launches your app properly. Your current payload only uses the top-level notification object, which might not be enough in some cases.
3. Incomplete Payload Structure
While click_action is present, combining it with a data payload can help Flutter handle the notification click more reliably, especially if you need to pass additional data to the app.
Correct C# Payload Format
Here's a fixed payload that addresses the above issues and ensures the notification launches your app:
Basic Working Payload
var payload = new { notification = new { icon = "your_icon_link", badge = 1, // Numeric value for Android badge title = "New Notification", body = "Message here", click_action = "FLUTTER_NOTIFICATION_CLICK", renotify = true }, data = new { // Optional: Add any custom data you want to pass to the app screen = "home", messageId = "12345" }, android = new { priority = "high", notification = new { click_action = "FLUTTER_NOTIFICATION_CLICK" } } };
Key Improvements:
- Changed
badgeto a numeric value (required for Android) - Added an
androidobject to explicitly set the click action for Android devices - Included a
dataobject (optional but recommended) to support deeper app navigation or data passing
Additional Checks
Verify AndroidManifest.xml: Double-check that your intent filter is placed inside the
<activity>tag that launches your app (usually the main Flutter activity):<activity android:name=".MainActivity" android:exported="true"> <intent-filter> <action android:name="FLUTTER_NOTIFICATION_CLICK" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> <!-- Your existing launcher intent filter --> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>Note: Using
DEFAULTcategory instead ofLAUNCHERfor theFLUTTER_NOTIFICATION_CLICKaction is more appropriate, as it allows the activity to be launched from the notification without conflicting with the launcher intent.Flutter Firebase Messaging Setup: Ensure you're handling notification clicks in your Flutter code using the
firebase_messagingpackage:FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) { // Handle the notification click, e.g., navigate to a specific screen print('Notification clicked!'); });
This should resolve the issue where clicking the notification doesn't launch your app. Test this payload and let me know if you run into any further issues!
内容的提问来源于stack exchange,提问作者Dinesh

