FCM push notification not working when app is closed Android FCM push notification not working when app is closed Android curl curl

FCM push notification not working when app is closed Android


I had the same problem. And this helped me.

Please remove "notification" key from payload and provide only "data" key.

Application handles notification messages only if the app is in foreground but it handles data messages even if the application is in background or closed.

If the application is in the foreground onMessageReceived handle both data and notification messages. If the application is closed or in the background only data messages are delivered to onMessageReceived . notification messages are not delivered to onMessageReceived . So you can't customize your messages.

It would be better to remove notification key from payload.


One Solution is as AmAnDroid Gave.

2nd solution is: Unfortunately this was a limitation of Firebase Notifications in SDK 9.0.0-9.6.1. When the app is in the background the launcher icon is use from the manifest (with the requisite Android tinting) for messages sent from the console.

With SDK 9.8.0 however, you can override the default! In your AndroidManifest.xml you can set the following fields to customise the icon and color:

Add below code in menifest:

 <meta-data        android:name="com.google.firebase.messaging.default_notification_icon"        android:resource="@drawable/com_facebook_button_send_icon_blue" />    <meta-data android:name="com.google.firebase.messaging.default_notification_color"        android:resource="@color/bt_blue_pressed" />

Body/Payload:

{ "notification":  {   "title": "Your Title",   "text": "Your Text",   "click_action": "MAIN_ACTIVITY" // should match to your intent filter }, "data":  {   "keyname": "any value " //you can get this data as extras in your activity and this data is optional }, "to" : "to_id(firebase refreshedToken)"} 

After with this add below code(intent-filter) in your acivity to be called:

<activity        android:name="MainActivity"        android:screenOrientation="portrait">        <intent-filter>            <action android:name="MAIN_ACTIVITY" />            <category android:name="android.intent.category.LAUNCHER" />        </intent-filter> </activity>

Make sure your Body/Payload's "click_action": "MAIN_ACTIVITY" and intent-filter's android:name="MAIN_ACTIVITY" should match.