Android平台FCM推送问题求助:接收推送时FirebaseMessagingService无日志输出
Hey there, let's work through this FCM logging issue—nothing's more frustrating than trying to debug push notifications and not seeing your logs, right? Here are the most common fixes to check:
1. Double-Check Your Service Registration
First, make sure your FirebaseMessagingService is properly declared in your AndroidManifest.xml:
<service android:name=".MyFirebaseMessagingService" android:exported="false"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service>
Also confirm you're correctly extending the service and overriding the right method:
- Kotlin:
class MyFirebaseMessagingService : FirebaseMessagingService() { private val TAG = "MyFCMService" override fun onMessageReceived(remoteMessage: RemoteMessage) { Log.d(TAG, "Received FCM message: ${remoteMessage.data}") // Rest of your logic } } - Java:
public class MyFirebaseMessagingService extends FirebaseMessagingService { private static final String TAG = "MyFCMService"; @Override public void onMessageReceived(RemoteMessage remoteMessage) { Log.d(TAG, "Received FCM message: " + remoteMessage.getData()); // Rest of your logic } }
2. Know the Difference Between Notification vs. Data Messages
FCM handles messages differently based on their type:
- Notification messages: When your app is in the background, the system displays the notification directly—your
onMessageReceivedwon't be triggered, so no logs will show up. This is expected behavior! - Data messages: These are delivered to
onMessageReceivedregardless of your app's state (foreground/background/killed).
To test, send a pure data message like this (via Firebase Console or your server):
{ "data": { "title": "Test Data Message", "body": "This should trigger onMessageReceived" }, "to": "YOUR_DEVICE_TOKEN" }
3. Verify Logcat Configuration
- Log level: If you're using
Log.d()(debug level), make sure Logcat's filter is set to "Debug" instead of "Info" or "Error". Alternatively, switch toLog.i()orLog.e()temporarily to see if logs appear. - Tag filtering: Use your service's TAG (like
MyFCMService) in Logcat's search bar to filter out noise—this makes it way easier to spot your logs among thousands of others.
4. Check for Device-Specific Background Restrictions
Many Android manufacturers (like Xiaomi, Samsung, Huawei) have aggressive battery optimization that kills background services. Try these steps:
- Test with your app in the foreground first—if logs show up here, the issue is likely background restrictions.
- Go to your device's Settings > Battery > Battery Optimization, find your app, and set it to "Not Optimized".
5. Update Firebase Dependencies
Outdated Firebase Messaging libraries can cause unexpected behavior. Make sure you're using the latest stable version in your build.gradle (Module level):
dependencies { implementation 'com.google.firebase:firebase-messaging:23.4.0' // Check for latest version }
If none of these fix the issue, feel free to share more details—like your manifest snippet, the exact message payload you're sending, or a screenshot of your Logcat. We can dig deeper!
内容的提问来源于stack exchange,提问作者yankel melloul

