You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter应用点击C#推送通知无法启动问题排查及正确Payload配置咨询

Troubleshooting Push Notification Launch Issue in Flutter (C# Sender)

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 badge to a numeric value (required for Android)
  • Added an android object to explicitly set the click action for Android devices
  • Included a data object (optional but recommended) to support deeper app navigation or data passing

Additional Checks

  1. 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 DEFAULT category instead of LAUNCHER for the FLUTTER_NOTIFICATION_CLICK action is more appropriate, as it allows the activity to be launched from the notification without conflicting with the launcher intent.

  2. Flutter Firebase Messaging Setup: Ensure you're handling notification clicks in your Flutter code using the firebase_messaging package:

    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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 18:07:30