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

自定义外观的Android通知:FCM使用及近三月失效问题求助

Hey there, let's dig into why your FCM data messages have stopped working over the last three months. I’ve put together a step-by-step troubleshooting checklist to help you narrow down the issue:

FCM Data Message Troubleshooting Guide
  • Check FCM SDK & Dependency Versions
    Outdated SDKs often clash with Google’s updated FCM infrastructure. Pop into your build config files (like build.gradle for Android) to confirm you’re using the latest stable firebase-messaging version. Don’t forget to check Google Play Services dependencies too—mismatched versions here are a common culprit for broken message delivery.

  • Verify Device-Level Restrictions
    Aggressive battery optimization or background app limits on many Android devices can kill the FCM connection. For example:

    • On Samsung: Head to Settings > Battery and device care > Battery > Background usage limits
    • On Xiaomi: Check Settings > Battery & performance > App battery saver
      Make sure your app is exempted from these restrictions—they can prevent OnMessageReceived from triggering when the app is in the background.
  • Validate Your Message Payload
    Data messages rely entirely on the data node (no predefined "notification" key). Double-check your server-side payload to ensure it’s formatted correctly. A valid example looks like this:

    {
      "to": "YOUR_DEVICE_TOKEN",
      "data": {
        "title": "Custom Alert",
        "body": "Your message content here",
        "custom_metadata": "any_value"
      }
    }
    

    Mixing notification fields with data fields can cause unexpected behavior, especially when the app is foregrounded vs. backgrounded.

  • Review FCM Console Logs & Reports
    Jump into the Firebase Console’s Cloud Messaging section and check the Logs and Reports tabs. Look for delivery failures, invalid tokens, or quota errors. Expired device tokens (from app reinstalls or data clears) or hitting sending limits are frequent issues here.

  • Test with a Minimal Payload
    Send a stripped-down data message directly from the Firebase Console to a test device. If this works, the problem is likely in your server-side implementation (e.g., incorrect token handling, payload typos). Even console-sent messages failing points to device-side configuration issues.

  • Confirm OnMessageReceived Setup
    Make sure your FirebaseMessagingService subclass is properly registered in your AndroidManifest.xml. The service declaration must include the correct intent filter:

    <service
        android:name=".YourMessagingService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
    

    Also, avoid blocking the main thread in OnMessageReceived—the system might kill the service before it can process the message.

  • Check Network Access
    Restricted networks (corporate proxies, VPNs) can block FCM’s endpoints. Ensure the device can reach fcm.googleapis.com and related domains. Test by switching to a different network (like home Wi-Fi) to see if messages come through.

  • Review Recent App Updates
    Think back to changes made around the time notifications stopped working. Did you add new permissions, modify background service behavior, or integrate a third-party library that could conflict with FCM? Roll back recent updates incrementally to spot a breaking change.


内容的提问来源于stack exchange,提问作者Haidar Hammoud

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 08:19:26